Record validation before save

K

Kman

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.
 
T

tina

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top