Solved

access 2007 vba Dcount() new problem

Posted on 2010-11-08
7
518 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
  • 3
  • 2
  • 2
7 Comments
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 500 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
Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Access 2016 - Labels prompt to print 4 34
Access 2016 7 36
DCount Type Mismatch 2 23
Progress bar in access form 11 26
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

825 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