Log in

View Full Version : update old record value with current record (in a form)



OTWarrior
02-08-2008, 02:39 AM
I am trying to update the value of a record in a table with a value from another record in the same table (in this case, the end date minus one day). The code doesn't always need to be run, as there are times when openargs are not used to open this form.

The problem I am having is getting the code to update the information in the record. I put a watch on the "If (tb.Fields(0) = OpenArgs) Then
" line for when the value matches my test data, and sure enough it stops when it hits that value. unfortunately, it doesn't move onto the next line, only onto the final "end if" statement, and I am unsure why.

If OpenArgs = vbNull Then
Else
Dim tb As DAO.Recordset
Set tb = CurrentDb.OpenRecordset("tbl_bookings", dbOpenDynaset)
tb.MoveFirst
Do While Not tb.EOF
If (tb.Fields(0) = OpenArgs) Then
tb.Edit
tb.Fields(7) = [dteStartDate] - 1 ' End Date
tb.Fields(13) = False ' UFN
tb.Update
End If
tb.MoveNext
Loop
End If

Any thoughts?

OTWarrior
02-08-2008, 03:31 AM
additionally shoudl both of these work, would this be more efficient and faster than the above?

DoCmd.RunSQL ("UPDATE tbl_bookings SET tbl_bookings.dteEndDate = [dteStartDate]-1, _
tbl_bookings.boolUFN = False WHERE (((tbl_bookings.anBookingID)=OpenArgs));")

rconverse
02-08-2008, 10:22 AM
If OpenArgs = vbNull Then


Else '<==What is this for?

Dim tb As DAO.Recordset Set tb = CurrentDb.OpenRecordset("tbl_bookings", dbOpenDynaset)
tb.MoveFirst
Do While Not tb.EOF
If (tb.Fields(0) = OpenArgs) Then
tb.Edit
tb.Fields(7) = [dteStartDate] - 1 ' End Date
tb.Fields(13) = "False" ' UFN
tb.Update
End If
tb.MoveNext
Loop
End If




Not sure that is going to solve your issue, but it looks like you'll need quotes around False, if you get the code to that point. You may need quotes for open args as well.

HTH
Roger