Link to home
Create AccountLog in
Avatar of gbnorton
gbnortonFlag for United States of America

asked on

Access 2007 VBA DCount() problem

I'm using this code:

If DCount("[Part_Number]", "Etching_Schedule", "[Part_Number] = 'Me.txtPart_Number'") > 0 Then
            MsgBox "That part number already exists for that date and shift."
End If

The code executes without error.  That part number does exist and it should go to the message box, but does not.

If I change the > to =, the message box does come up.

I don't understand why it is not finding the matching record.

Thanks,
Brooks
ASKER CERTIFIED SOLUTION
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
If DCount("[Part_Number]", "Etching_Schedule", "[Part_Number] = '" & Me.txtPart_Number &"'") > 0 Then


Me.txtPart_Number  must be aoutside the double quotes for it to be evaluated
Avatar of gbnorton

ASKER

Would you provide an example for the DATE data type?
Thanks,
Brooks


If DCount("[Part_Number]", "Etching_Schedule", "[Part_Number] = '" & Me.txtPart_Number &"' And [datefield]=#" & date() & "#") > 0 Then