If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
Record validation before save
Hi,
I am trying to validate that a record doesn't exist in a table before saving using a dlookup function, however I keep getting a "type mismatch" on runtime. Can anyone help, here is the code: Private Sub Form_BeforeUpdate(Cancel As Integer) Dim strWhere As String Dim varResult As Variant varResult = DLookup("TimeOn", "TimeOn", "EmployeeID = " & Forms!ClockOn!EmployeeID _ & " AND DateIn =#" & Forms!ClockOn!DateIn & "#") If IsNull(varResult) Then MsgBox "Your Time On record has been successfully recorded", vbOK 'Cancel = True 'Me.Undo End If End Sub Any assistance greatly appreciated. |
#2
|
|||
|
|||
Record validation before save
well, nothing jumped up and bit me on the nose. so you need to troubleshoot.
first, put a break in the code to see what line is generating the error. then start checking that line - values assigned to variables, values in referenced controls. and doublecheck the data types of referenced fields in tables. you're looking for mismatched data types: a number compared to a string, a string compared to a date, etc. hth "Kman" wrote in message ... Hi, I am trying to validate that a record doesn't exist in a table before saving using a dlookup function, however I keep getting a "type mismatch" on runtime. Can anyone help, here is the code: Private Sub Form_BeforeUpdate(Cancel As Integer) Dim strWhere As String Dim varResult As Variant varResult = DLookup("TimeOn", "TimeOn", "EmployeeID = " & Forms!ClockOn!EmployeeID _ & " AND DateIn =#" & Forms!ClockOn!DateIn & "#") If IsNull(varResult) Then MsgBox "Your Time On record has been successfully recorded", vbOK 'Cancel = True 'Me.Undo End If End Sub Any assistance greatly appreciated. |
Thread Tools | |
Display Modes | |
|
|