Solved

Access VBA 3464: Data type mismatch in criteria expression.

Posted on 2014-09-09
10
747 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
 
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
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 

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 119

Assisted Solution

by:Rey Obrero
Rey Obrero 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

930 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now