Solved

Access 2007 VBA DCount() problem

Posted on 2010-11-08
4
911 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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

820 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