Solved

Access VBA 3464: Data type mismatch in criteria expression.

Posted on 2014-09-09
10
773 Views
Last Modified: 2014-09-15
I have this query which works in Access: -
Sql = "SELECT dbo_MdnMaster.DispatchNote, IIf(isnull([DeliveredQty]),'X',IIf([OriginalDespatchQty]-[DeliveredQty]<>0,'X','OK')) AS CheckIt "
Sql = Sql & "FROM dbo_MdnMaster INNER JOIN (dbo_Job INNER JOIN dbo_JobDetail ON dbo_Job.JobID = dbo_JobDetail.JobID) ON dbo_MdnMaster.DispatchNote = dbo_Job.JobRef3 "
Set Rst = Dbs.OpenRecordset(Sql)
Dim txtCheck
txtCheck = Rst!CheckIt

Open in new window


It fails on the last line, can anyone help?
0
Comment
Question by:HKFuey
  • 4
  • 2
  • 2
  • +2
10 Comments
 
LVL 84
ID: 40311763
What do you mean by "fail"? Do you get an error? If so, then post the details of that error.

If you post the SQL into a query in Access, does it return records as expected?
0
 

Author Comment

by:HKFuey
ID: 40311820
Check the title : )

Re: If you post the SQL into a query in Access, does it return records as expected?

Yes
0
 
LVL 49

Expert Comment

by:Gustav Brock
ID: 40311853
Try with:

If Rst.RecordCount > 0 Then
    Rst.MoveFirst
    txtCheck = Rst!CheckIt.Value
End If

/gustav
0
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.

 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 300 total points
ID: 40311863
the test on EOF is indeed requested...
also please data-type all your variables correctly:
Dim txtCheck as string

anyhow, the error you get is likely about either value data type issues for the JOIN ... ON conditions
Sql = "SELECT dbo_MdnMaster.DispatchNote, IIf(isnull([DeliveredQty]),'X',IIf([OriginalDespatchQty]-[DeliveredQty]<>0,'X','OK')) AS CheckIt "
Sql = Sql & "FROM dbo_MdnMaster INNER JOIN (dbo_Job INNER JOIN dbo_JobDetail ON ( dbo_Job.JobID = dbo_JobDetail.JobID) ) ON ( dbo_MdnMaster.DispatchNote = dbo_Job.JobRef3 ) "
Set Rst = Dbs.OpenRecordset(Sql)
Dim txtCheck as string
if not (Rst.eof and Rst.bof ) then
  txtCheck = Rst!CheckIt
end if

Open in new window

0
 
LVL 84
ID: 40311876
Check the title : )
Would have been nice had you pointed out that 3464 was an ERROR. We can't read your mind, so in the future if you want to indicate that in your title, please write something like "Access VBA Error 3464 blah blah"

:)
0
 

Author Comment

by:HKFuey
ID: 40311938
Hi Gustav,
I am checking for a record. I think the problem must be a null record in the formula as
txtCheck = Rst!Barcode works fine.

Hi Guy, I tried both: Dim txtCheck  and Dim txtCheck as string.

The query in Access returns 'X' for this formula when 'DeliveredQty' is null : -
IIf(isnull([DeliveredQty]),'X',IIf([OriginalDespatchQty]-[DeliveredQty]<>0,'X','OK')) AS CheckIt "
0
 
LVL 120

Assisted Solution

by:Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1) earned 100 total points
ID: 40311942
try using the Nz() function

 txtCheck = Nz(Rst!CheckIt,"")

or place a meaningful substitute for null

 txtCheck = nz(Rst!CheckIt,"nothing")
0
 
LVL 49

Assisted Solution

by:Gustav Brock
Gustav Brock earned 100 total points
ID: 40311958
OK. Then you may simply need:

    IIf(Nz([OriginalDespatchQty]-[DeliveredQty], 0) = 0,'OK', 'X') AS CheckIt " 

/gustav
0
 

Assisted Solution

by:HKFuey
HKFuey earned 0 total points
ID: 40312284
Hi Guy,
Re: "anyhow, the error you get is likely about either value data type issues"

The field I assumed was null was actually a space DUH!!!!!!!.
0
 

Author Closing Comment

by:HKFuey
ID: 40322715
Thanks to all who tried to help!
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

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…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
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…

770 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