Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Access 2007 VBA DCount() problem

Posted on 2010-11-08
4
Medium Priority
?
936 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 2000 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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
Instead of error trapping or hard-coding for non-updateable fields when using QODBC, let VBA automatically disable them when forms open. This way, users can view but not change the data. Part 1 explained how to use schema tables to do this. Part 2 h…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

715 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