Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 941
  • Last Modified:

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
0
gbnorton
Asked:
gbnorton
  • 2
1 Solution
 
Rey Obrero (Capricorn1)Commented:
if  [Part_number] is Text Data type, use this


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


if  [Part_number] is NUMBER Data type, use this


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
0
 
peter57rCommented:
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
0
 
gbnortonAuthor Commented:
Would you provide an example for the DATE data type?
Thanks,
Brooks
0
 
Rey Obrero (Capricorn1)Commented:


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

Featured Post

Microsoft Certification Exam 74-409

VeeamĀ® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now