Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 10th, 2005, 11:23 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default Data Type Mismatch Error in Criteria Expression

Okay, this one is bothering me:

I have two combo boxes on a form, one with a list value of 1-12, and the other with a list value of 2004, and 2005.

The user uses the combo boxes to select a month and year, then clicks a button to pull up a report with data for that month and year. Here is code THAT WORKS:

'=====Code Starts=====
    Dim stDocName As String
    Dim stMonth As String
    Dim stYear As String
    Dim stLinkCriteria As String

    stMonth = Me.Combo11
    stYear = Me.Combo13

    stLinkCriteria = "[Month] = " & "'" & stMonth & "'" & " And " & "[Year] = " & "'" & stYear & "'"

    stDocName = "rptqryROUNDEDCPUSpeed2"
    DoCmd.OpenReport stDocName, acPreview, , stLinkCriteria
'=====Code Ends=====

I built a second report from the same table only changing the CPU speed to RAM quantity, using the same combo boxes but pulling up a similar report, and this code DOES NOT WORK:

'=====Code Starts=====
    Dim stDocName As String
    Dim stMonth As String
    Dim stYear As String
    Dim stLinkCriteria As String

    stMonth = Me.Combo11
    stYear = Me.Combo13
    stLinkCriteria = "[Month] = " & "'" & stMonth & "'" & " And " & "[Year] = " & "'" & stYear & "'"

    stDocName = "rptqryRAMSPEED"
    DoCmd.OpenReport stDocName, acPreview, , stLinkCriteria
'=====Code Ends=====

So the very same code works for one report, but not the other. With the second report I get the error listed in the subject line.

What am I overlooking?

mmcdonal
__________________
mmcdonal

Look it up at: http://wrox.books24x7.com
 
Old January 10th, 2005, 03:45 PM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

C'mon people! Once again I found the answer before it was posted here:

stLinkCriteria = "[Month] = " & stMonth & " And " & "[Year] = " & stYear

I was passing integers with single quotes. Oddly this works 95% of the time. Just once in awhile it doesn't and that made me sloppy copying and pasting code.

I hope this helps someone else.

mmcdonal
 
Old March 1st, 2007, 05:18 PM
Registered User
 
Join Date: Mar 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

2 years later I read this for a similar issue - yes, this did help me... thx!






Similar Threads
Thread Thread Starter Forum Replies Last Post
data type mismatch in criteria expression coreyjustin Classic ASP Basics 1 December 10th, 2007 06:49 PM
Data type mismatch in criteria expression. imercha Classic ASP Basics 3 November 23rd, 2006 11:09 AM
Data type mismatch in criteria expression. EDEN Access ASP 1 November 22nd, 2006 01:19 AM
Data Type Mismatch in criteria expression dreviklou812 Access 4 March 18th, 2005 04:42 PM
Data type mismatch in criteria expression mrideout BOOK: Beginning ASP.NET 1.0 0 August 25th, 2004 05:32 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.