Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

access 2007 vba Dcount() new problem

Posted on 2010-11-08
7
Medium Priority
?
552 Views
Last Modified: 2012-05-10
The code:

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

It fails with runtime error 13 data mismatch.  There is something about the:
And "[Run_Date] = #" & Me.dteRun_Date & "#"

The Run_Date field is a date/time field but only the date is saved.

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
  • 3
  • 2
  • 2
7 Comments
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 2000 total points
ID: 34086556


try this

If DCount("[Part_Number]", "Etching_Schedule", "[Part_Number] = '" & Me.txtPart_Number & "' And [Run_Date] = #" & Me.dteRun_Date & "#") > 0 Then
            MsgBox "That part number already exists for that date."
End If
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 34086563
is the field [Run_Date] DateTime data type?
0
 

Author Comment

by:gbnorton
ID: 34086598
Yes.  It is DateTime data type
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 34086618
ok, try the codes i posted above..
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 34086637
try using format or datevalue and wrap your field with cdate in case its been defined as a text field
plus split it up to make it more readable

eg

    Dim sWhere As String
   
    sWhere = "[Part_Number] = '" & Me.txtPart_Number & "' AND DateValue([Run_Date]) = #" & CDate(Me.dteRun_Date) & "#"

OR

    sWhere = "[Part_Number] = '" & Me.txtPart_Number & "' AND Format([Run_Date],'Short Date') = #" & CDate(Me.dteRun_Date) & "#"
   

    If DCount("[Part_Number]", "Etching_Schedule", sWhere) > 0 Then
        MsgBox "That part number already exists for that date."
    End If
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 34086653
If you just store the date and not the time, you can try without using datevalue or format, see if that makes a difference
eg

sWhere = "[Part_Number] = '" & Me.txtPart_Number & "' AND [Run_Date] = #" & CDate(Me.dteRun_Date) & "#"

so basically just wrap field with cdate
0
 

Author Closing Comment

by:gbnorton
ID: 34086660
It took me a minute to see the difference between the new code and mine... but I filnally did see it and it works.  Thanks
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
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…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

604 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