Update current record only

esskaykay

Registered User.
Local time
Today, 08:54
Joined
Mar 8, 2003
Messages
267
Is there a way to run code against only the current record? I would like to update a date field with the current date only if the field is null.

CODE:
If RequestDate > 0 Then
GoTo GoodBye
Else
DoCmd.RunSQL "UPDATE tblRequests SET tblRequests.RequestDate = Date()"
DoCmd.RepaintObject
End If

I tried placing the code in the OnCurrent property of a form the opens but it still updated all null records not just the current one.

Also, what is the syntax for null date? I tried “If RequestDate is null 0 Then” but it did not work so I went to the >0 option.

Thanks,
SKK
 
The way to run SQL against a particular record is to add a WHERE clause, for instance:

DoCmd.RunSQL "UPDATE tblRequests SET tblRequests.RequestDate = Date() WHERE IDField = " & Me.IDField
 
Last edited:
Excellent - thank you very much Paul. I've got a few other issues right now but I'm really close.

Just one other question. What is the code to test for null date? Like I said, I'm using >0 which is working, but I'm sure there's a more proper way to test for this.

Thanks again,
SKK
 
I often use:

If IsDate(...) Then

If you want to explicitly test for Null:

If IsNull(...) Then
 

Users who are viewing this thread

Back
Top Bottom