Help editing record set

D

Daniel M

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
 
R

ruralguy via AccessMonster.com

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 said:
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]
 
D

Daniel M

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 said:
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 said:
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
 
D

Daniel M

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 said:
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 said:
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 said:
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
 
R

ruralguy via AccessMonster.com

How about:
If Rs("departmentid") = Val(txtDID.Value) Then
or
If CStr(Rs("departmentid")) = txtDID.Value Then

Daniel said:
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]
 
D

Daniel M

That works too. :) thanks.

ruralguy via AccessMonster.com said:
How about:
If Rs("departmentid") = Val(txtDID.Value) Then
or
If CStr(Rs("departmentid")) = txtDID.Value Then

Daniel said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top