Updating Record Through a Form (1 Viewer)

adidab14

New member
Local time
Today, 12:51
Joined
Apr 23, 2019
Messages
7
Hello there,
I am trying to update a record through a form based on an unbound text box and a null value but I'm having a little trouble getting the code to work. I'm hoping that someone here can help me.
Basically I'm looking to add a timestamp to a specific field (TimeOut) if the record contains the value in the text box AND a null value in the TimeOut field.

So my variables here are:
Table where all of this is found = Test
Field that needs to match the text box = MoldNumber
Text Box = txtMold
Field that I need updated if it has a null value = TimeOut.

Here's the code I'm trying but failing with:

Code:
CurrentDb.Execute "UPDATE Test SET TimeOut = #" & Now() & "# WHERE MoldNumber= '" & Me!TxtMold & "'", IsNull(TimeOut), dbFailOnError

I'm not terribly well versed in VBA but I just can't seem to figure this out. Any help would be greatly appreciated!
 

theDBguy

I’m here to help
Staff member
Local time
Today, 12:51
Joined
Oct 29, 2018
Messages
21,358
Hi. You were almost there. I would try it this way:
Code:
Dim strSQL As String


strSQL = "UPDATE Test SET TimeOut=Now() WHERE TimeOut Is Null AND MoldNumber='" & Me.txtMold & "'"


Debug.Print strSQL


CurrentDb.Execute strSQL, dbFailOnError
Hope it helps...
 

adidab14

New member
Local time
Today, 12:51
Joined
Apr 23, 2019
Messages
7
That worked like a charm. You are amazing! :)
 

Users who are viewing this thread

Top Bottom