Solved Dlookup Mismatch error (1 Viewer)

Poco_90

Registered User.
Local time
Today, 01:47
Joined
Jul 26, 2013
Messages
87
I know (I actually don't :)) it is somthing stupid. I had this DLookup working but for some reason now it isn't. When it was working I had me.txtSerial, but with tiral an derror and other fourm suggestions it has changed to below.

Code:
If DLookup("[Serial Number]", "[tblPassed]", "[Serial Number] ='" & [Forms]![frmValidation]![txtSerial] & "'") Then
                          MsgBox "Serial Number is Good"

It is embarassing how long I have spent trying to resolve this, but would appreciate any input.


I have a form(frmValidation) that is taking in a delimited string into a field. I am splitting the elements of the string into individaul text boxes, one being txtSerial, and my aim os to see if this value is in the tblPassed table.

Thanks in advance.
 

GaP42

Active member
Local time
Today, 10:47
Joined
Apr 27, 2020
Messages
338
{Serial Number] is defined as of type integer? and txtSerial - is a string. Need to convert
 

jdraw

Super Moderator
Staff member
Local time
Yesterday, 20:47
Joined
Jan 23, 2006
Messages
15,379
Can you post a copy of the database with info to highlight the issue?

Is there any more to the error message?
 

Gasman

Enthusiastic Amateur
Local time
Today, 01:47
Joined
Sep 21, 2011
Messages
14,310
If serial number is numeric, remove the single quotes from your form control. However, why would you lookup a serial number, using the serial number you already have? and not test equal :(
Perhaps use Dcount() with same criteria > 0
 

XPS35

Active member
Local time
Today, 02:47
Joined
Jul 19, 2022
Messages
159
The DLookup will return the value of er serial number. If .... Then expects an expression that is True or False where the .... are.
I think that is why you get a type mismatch.
 

MajP

You've got your good things, and you've got mine.
Local time
Yesterday, 20:47
Joined
May 21, 2018
Messages
8,529
Code:
if Dcount("*", "[tblPassed]", "[Serial Number] ='" & [Forms]![frmValidation]![txtSerial] & "'") > 0 Then
                          MsgBox "Serial Number is Good"
 

plog

Banishment Pending
Local time
Yesterday, 19:47
Joined
May 11, 2011
Messages
11,646
Your If will never resolve to False. Never. It can only be True or throw an error.

Even if you have a serial number that is literally "FALSE", that will resolve to True. If it doesn't find the serial number at all it will blow up and throw an error, which is what I believed happened. You should not use DLookup you should use DCount. MajP has provided an example.

Additionally, you are not doing yourself any favors by having spaces in field names (e.g. [Serial Number]). It just makes coding and querying that much more difficult. Only use alphanumeric and underscores in Access names.
 

Poco_90

Registered User.
Local time
Today, 01:47
Joined
Jul 26, 2013
Messages
87
I don't know what happened. I posted the DB 4 hours ago but it only seem to go through now. Thanks for the replies and advice I appreciate it. I will try MajP suggestion.

The spaces in the field names are not by my design...Too many cooks!
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 08:47
Joined
May 7, 2009
Messages
19,245
you can also try:
Code:
    If DCount("1", "[tblPassed]", "[Customer Part Number] ='" & LArray(0) & "' And " & _
                "[Part Number] = '" & LArray(1) & "' And [Serial Number] = '" & LArray(2) & "'") <> 0 Then
                          MsgBox "SerialNumber is Good"
    Else
        MsgBox "SerialNumber is Bad, please double check"
        Exit Sub
    End If
 

Isaac

Lifelong Learner
Local time
Yesterday, 17:47
Joined
Mar 14, 2017
Messages
8,777
Dim serial As Variant
serial = DLookup("[Serial Number]", "[tblPassed]", "[Serial Number] ='" & [Forms]![frmValidation]![txtSerial] & "'")
If Not IsNull(serial) Then
MsgBox "Serial Number is Good"
Else
MsgBox "Serial Number not found"
End If
 

Poco_90

Registered User.
Local time
Today, 01:47
Joined
Jul 26, 2013
Messages
87
Thanks again for all the suggestions, tried them all and they all worked as expected. Now I am spoilt for choice!
 

Users who are viewing this thread

Top Bottom