DarkBrewer
New member
- Local time
- Today, 15:21
- Joined
- Sep 14, 2022
- Messages
- 12
Howdy,
I've been struggling with this for a bit and suspect I'm missing something simple or not doing it in an appropriate manner. I have a form that takes user input and it works to update a record if it doesn't exist like I'm expecting. My struggle pertains to checking to see if the value exists, and if it does, add a record to a different field.
Here is the code I'm using:
Option Compare Database
Option Explicit
Private Sub Text0_Enter()
Dim rs As Recordset
Dim strCriteria As String
Set rs = CurrentDb.OpenRecordset("Table1", dbOpenDynaset)
On Error GoTo ErrHandler
If IsNull(Me.Text0.Value) Then
MsgBox ("Please enter the Job Number.")
Exit Sub
End If
'area I can't figure out and obviously not structing Dlookup correctly'
If (DLookup("JobName", "Table1", "JobName" = Me.Text0.Value"))Then
rs.AddNew
rs.Fields("TimeOut").Value = Now()
rs.Update
Else
rs.AddNew
rs.Fields("JobName").Value = Me.Text0.Value
rs.Fields("TimeIn").Value = Now()
rs.Update
End If
Exit Sub
ErrHandler:
MsgBox Err.Description, vbExclamation, "Error Occurred"
End Sub
What would I need to change in the Dlookup to check for the value being provided from the input textbox?
I've been struggling with this for a bit and suspect I'm missing something simple or not doing it in an appropriate manner. I have a form that takes user input and it works to update a record if it doesn't exist like I'm expecting. My struggle pertains to checking to see if the value exists, and if it does, add a record to a different field.
Here is the code I'm using:
Option Compare Database
Option Explicit
Private Sub Text0_Enter()
Dim rs As Recordset
Dim strCriteria As String
Set rs = CurrentDb.OpenRecordset("Table1", dbOpenDynaset)
On Error GoTo ErrHandler
If IsNull(Me.Text0.Value) Then
MsgBox ("Please enter the Job Number.")
Exit Sub
End If
'area I can't figure out and obviously not structing Dlookup correctly'
If (DLookup("JobName", "Table1", "JobName" = Me.Text0.Value"))Then
rs.AddNew
rs.Fields("TimeOut").Value = Now()
rs.Update
Else
rs.AddNew
rs.Fields("JobName").Value = Me.Text0.Value
rs.Fields("TimeIn").Value = Now()
rs.Update
End If
Exit Sub
ErrHandler:
MsgBox Err.Description, vbExclamation, "Error Occurred"
End Sub
What would I need to change in the Dlookup to check for the value being provided from the input textbox?