Dlookup freaking out

Pyro

Too busy to comment
Local time
Tomorrow, 06:39
Joined
Apr 2, 2009
Messages
127
Hi, i am trying to run the following piece of code:

Code:
If DLookup("lotno", "[tbl_track_expiry]", "lotno = '" & [txtlotno] & "'") Then
   If MsgBox("The Batch Number you are trying to enter already exists in the system." & vbCrLf & _
        " " & vbCrLf & _
        "Press OK to go to that record, or cancel to undo this entry.", vbOKCancel, "Alert") = vbOK Then
            Me.RecordsetClone.FindFirst "[track_expiry_lotno] = '" & [txtlotno] & "'"
            Me.undo
            Me.Bookmark = Me.RecordsetClone.Bookmark
 
    Else
        Me.undo
 
    End If
 
Else
    Me.txtlotno = Me.txtlotno
 
End If

If the value that it is checking is numeric, everything works fine. If it is a string, i get "Run-time error '13': Type Mismatch". The field in the table has stored text and numeric values. The form is built on a query of multiple tables.

Any ideas as to what is going on?
 
Check the data type of lotno in the table.I think its number so Dlookup is giving you problem when you enter any text(string) in lotno. Change the data type to string and everything will be fine.

Cheers
 
Actually Your If DLookup is returning a boolean value you need to change it to

If Nz(DLookup(),0) <> 0 Then
 

Users who are viewing this thread

Back
Top Bottom