Solved

Access 2007 VBA DCount() problem

Posted on 2010-11-08
4
904 Views
Last Modified: 2013-11-27
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
Comment
Question by:gbnorton
  • 2
4 Comments
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 500 total points
ID: 34085189
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
 
LVL 77

Expert Comment

by:peter57r
ID: 34085201
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
 

Author Comment

by:gbnorton
ID: 34085865
Would you provide an example for the DATE data type?
Thanks,
Brooks
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 34085889


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

Featured Post

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question