Solved

Access VBA 3464: Data type mismatch in criteria expression.

Posted on 2014-09-09
10
727 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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This script will sweep a range of IP addresses (class c only, 255.255.255.0) and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

757 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

15 Experts available now in Live!

Get 1:1 Help Now