Group:  Microsoft Access ยป microsoft.public.access.formscoding
Thread: Help editing record set

Geek News

Help editing record set
Daniel M 11/19/2008 4:43:01 PM
I have some code to edit a record set. I cannot seem to get it working. Can
someone take a look and tell me why? I have set the form text box (txtDID) to
the second record in the table (6). When i go throught the loop, the msgbox
displays 5=6. Fine that is wrong so it should reloop. the next loop i recieve
6=6 in the msgbox but it does not do the edit. it jumps out of the IF? Can
someone tell my why 6 is not = 6? Thanks.

Dim Rs As Recordset
Set Rs = CurrentDb.OpenRecordset("Departments")

Do While Not Rs.EOF

If Rs("departmentid") = txtDID.Value Then
Rs.Edit
Rs("DepartmentName") = txtCityState
Rs.Update
Rs.Close
End If
MsgBox Rs("departmentid") & " = " & txtDID.Value

Rs.MoveNext
Loop


Re: Help editing record set
"ruralguy via AccessMonster.com" <u12102[ at ]uwe> 11/19/2008 6:18:51 PM
Have you tried using the debugger to examine the values?

Daniel M wrote:
[Quoted Text]
>I have some code to edit a record set. I cannot seem to get it working. Can
>someone take a look and tell me why? I have set the form text box (txtDID) to
>the second record in the table (6). When i go throught the loop, the msgbox
>displays 5=6. Fine that is wrong so it should reloop. the next loop i recieve
>6=6 in the msgbox but it does not do the edit. it jumps out of the IF? Can
>someone tell my why 6 is not = 6? Thanks.
>
>Dim Rs As Recordset
>Set Rs = CurrentDb.OpenRecordset("Departments")
>
>Do While Not Rs.EOF
>
> If Rs("departmentid") = txtDID.Value Then
> Rs.Edit
> Rs("DepartmentName") = txtCityState
> Rs.Update
> Rs.Close
> End If
> MsgBox Rs("departmentid") & " = " & txtDID.Value
>
> Rs.MoveNext
>Loop

--
RuralGuy (RG for short) aka Allan Bunch MS Access MVP - acXP WinXP Pro
Please post back to this forum so all may benefit.

Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/Forums.aspx/access-formscoding/200811/1

Re: Help editing record set
Daniel M 11/19/2008 8:02:13 PM
I dont know how to do this, can you give me some help?

"ruralguy via AccessMonster.com" wrote:

[Quoted Text]
> Have you tried using the debugger to examine the values?
>
> Daniel M wrote:
> >I have some code to edit a record set. I cannot seem to get it working. Can
> >someone take a look and tell me why? I have set the form text box (txtDID) to
> >the second record in the table (6). When i go throught the loop, the msgbox
> >displays 5=6. Fine that is wrong so it should reloop. the next loop i recieve
> >6=6 in the msgbox but it does not do the edit. it jumps out of the IF? Can
> >someone tell my why 6 is not = 6? Thanks.
> >
> >Dim Rs As Recordset
> >Set Rs = CurrentDb.OpenRecordset("Departments")
> >
> >Do While Not Rs.EOF
> >
> > If Rs("departmentid") = txtDID.Value Then
> > Rs.Edit
> > Rs("DepartmentName") = txtCityState
> > Rs.Update
> > Rs.Close
> > End If
> > MsgBox Rs("departmentid") & " = " & txtDID.Value
> >
> > Rs.MoveNext
> >Loop
>
> --
> RuralGuy (RG for short) aka Allan Bunch MS Access MVP - acXP WinXP Pro
> Please post back to this forum so all may benefit.
>
> Message posted via AccessMonster.com
> http://www.accessmonster.com/Uwe/Forums.aspx/access-formscoding/200811/1
>
>
Re: Help editing record set
"ruralguy via AccessMonster.com" <u12102[ at ]uwe> 11/19/2008 8:54:49 PM
While looking at the code, click outside the left margin and a dot will
appear to indicate a breakpoint. Then run the code and it will stop on that
line. If you hover over the variables, their value will display in a baloon.
You can single step using the F8 key.

Daniel M wrote:
[Quoted Text]
>I dont know how to do this, can you give me some help?
>
>> Have you tried using the debugger to examine the values?
>>
>[quoted text clipped - 20 lines]
>> > Rs.MoveNext
>> >Loop

--
RuralGuy (RG for short) aka Allan Bunch MS Access MVP - acXP WinXP Pro
Please post back to this forum so all may benefit.

Message posted via http://www.accessmonster.com

Re: Help editing record set
Daniel M 11/19/2008 9:37:02 PM
It shows the following..

RS("departmentid") = 6
txtDID.value = "6"

so how do i get 6 to = "6" some how i have a type mismatch i think but i
dont know how to fix it.

"ruralguy via AccessMonster.com" wrote:

[Quoted Text]
> While looking at the code, click outside the left margin and a dot will
> appear to indicate a breakpoint. Then run the code and it will stop on that
> line. If you hover over the variables, their value will display in a baloon.
> You can single step using the F8 key.
>
> Daniel M wrote:
> >I dont know how to do this, can you give me some help?
> >
> >> Have you tried using the debugger to examine the values?
> >>
> >[quoted text clipped - 20 lines]
> >> > Rs.MoveNext
> >> >Loop
>
> --
> RuralGuy (RG for short) aka Allan Bunch MS Access MVP - acXP WinXP Pro
> Please post back to this forum so all may benefit.
>
> Message posted via http://www.accessmonster.com
>
>
Re: Help editing record set
Daniel M 11/19/2008 9:51:02 PM
ok, now that i post the message i answered my own question. "6" was a string
and 6 was an interger. i dim'ed a varialbe as integer and set txtDID.value =
to the varialble. now RS("departmentid") = variable works fine.

Thanks for poking me in the right direction.

"Daniel M" wrote:

[Quoted Text]
> It shows the following..
>
> RS("departmentid") = 6
> txtDID.value = "6"
>
> so how do i get 6 to = "6" some how i have a type mismatch i think but i
> dont know how to fix it.
>
> "ruralguy via AccessMonster.com" wrote:
>
> > While looking at the code, click outside the left margin and a dot will
> > appear to indicate a breakpoint. Then run the code and it will stop on that
> > line. If you hover over the variables, their value will display in a baloon.
> > You can single step using the F8 key.
> >
> > Daniel M wrote:
> > >I dont know how to do this, can you give me some help?
> > >
> > >> Have you tried using the debugger to examine the values?
> > >>
> > >[quoted text clipped - 20 lines]
> > >> > Rs.MoveNext
> > >> >Loop
> >
> > --
> > RuralGuy (RG for short) aka Allan Bunch MS Access MVP - acXP WinXP Pro
> > Please post back to this forum so all may benefit.
> >
> > Message posted via http://www.accessmonster.com
> >
> >
Re: Help editing record set
"ruralguy via AccessMonster.com" <u12102[ at ]uwe> 11/19/2008 9:55:21 PM
How about:
If Rs("departmentid") = Val(txtDID.Value) Then
or
If CStr(Rs("departmentid")) = txtDID.Value Then

Daniel M wrote:
[Quoted Text]
>It shows the following..
>
>RS("departmentid") = 6
>txtDID.value = "6"
>
>so how do i get 6 to = "6" some how i have a type mismatch i think but i
>dont know how to fix it.
>
>> While looking at the code, click outside the left margin and a dot will
>> appear to indicate a breakpoint. Then run the code and it will stop on that
>[quoted text clipped - 8 lines]
>> >> > Rs.MoveNext
>> >> >Loop

--
RuralGuy (RG for short) aka Allan Bunch MS Access MVP - acXP WinXP Pro
Please post back to this forum so all may benefit.

Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/Forums.aspx/access-formscoding/200811/1

Re: Help editing record set
Daniel M 11/19/2008 10:36:02 PM
That works too. :) thanks.

"ruralguy via AccessMonster.com" wrote:

[Quoted Text]
> How about:
> If Rs("departmentid") = Val(txtDID.Value) Then
> or
> If CStr(Rs("departmentid")) = txtDID.Value Then
>
> Daniel M wrote:
> >It shows the following..
> >
> >RS("departmentid") = 6
> >txtDID.value = "6"
> >
> >so how do i get 6 to = "6" some how i have a type mismatch i think but i
> >dont know how to fix it.
> >
> >> While looking at the code, click outside the left margin and a dot will
> >> appear to indicate a breakpoint. Then run the code and it will stop on that
> >[quoted text clipped - 8 lines]
> >> >> > Rs.MoveNext
> >> >> >Loop
>
> --
> RuralGuy (RG for short) aka Allan Bunch MS Access MVP - acXP WinXP Pro
> Please post back to this forum so all may benefit.
>
> Message posted via AccessMonster.com
> http://www.accessmonster.com/Uwe/Forums.aspx/access-formscoding/200811/1
>
>
Re: Help editing record set
"ruralguy via AccessMonster.com" <u12102[ at ]uwe> 11/20/2008 2:06:41 AM
Glad I could help. ;)

Daniel M wrote:
[Quoted Text]
>That works too. :) thanks.
>
>> How about:
>> If Rs("departmentid") = Val(txtDID.Value) Then
>[quoted text clipped - 14 lines]
>> >> >> > Rs.MoveNext
>> >> >> >Loop

--
RuralGuy (RG for short) aka Allan Bunch MS Access MVP - acXP WinXP Pro
Please post back to this forum so all may benefit.

Message posted via http://www.accessmonster.com

Home | Search | Terms | Imprint Contact
Newsgroups Reader - provided by WiredBox.Net