Help with dCount - “Data Type mismatch in criteria expressionâ€

F

FatMan

Hi all:
The code listed below is giving me a “Data Type mismatch in criteria
expression†error.

Code:
Me.txtBinsScanned = DCount("[BatchNum]", "[tblPreSortBatchBackup]",
"[BatchNum]=" & [Forms]![frmTraceBox]![txtBatch])


Where:
BatchNum data type is text

TxtBatch is a text box on my form that is getting its value through a
dlookup function and the results being returned are from a text field from a
different table. It works and the code for it is:

Me.txtBatch = DLookup("[InFriutTransLog]", "[tblIntake]", "[IntakeID]=" &
[Forms]![frmTraceBox]![txtIntakeID])

All help is greatly appreciated.

Thanks,
FatMan
 
D

Douglas J. Steele

Since BatchNum is text, the value being passed must be in quotes:

Me.txtBinsScanned = DCount("[BatchNum]", "[tblPreSortBatchBackup]",
"[BatchNum]='" & [Forms]![frmTraceBox]![txtBatch] & "'")

Exagerated for clarity, that's

"[BatchNum]= ' " & [Forms]![frmTraceBox]![txtBatch] & " ' ")
 
F

FatMan

Doug:
You da man!

Thanks,
FatMan

Douglas J. Steele said:
Since BatchNum is text, the value being passed must be in quotes:

Me.txtBinsScanned = DCount("[BatchNum]", "[tblPreSortBatchBackup]",
"[BatchNum]='" & [Forms]![frmTraceBox]![txtBatch] & "'")

Exagerated for clarity, that's

"[BatchNum]= ' " & [Forms]![frmTraceBox]![txtBatch] & " ' ")

--
Doug Steele, Microsoft Access MVP
http://www.AccessMVP.com/DJSteele
(no e-mails, please!)

FatMan said:
Hi all:
The code listed below is giving me a "Data Type mismatch in criteria
expression" error.

Code:
Me.txtBinsScanned = DCount("[BatchNum]", "[tblPreSortBatchBackup]",
"[BatchNum]=" & [Forms]![frmTraceBox]![txtBatch])


Where:
BatchNum data type is text

TxtBatch is a text box on my form that is getting its value through a
dlookup function and the results being returned are from a text field from
a
different table. It works and the code for it is:

Me.txtBatch = DLookup("[InFriutTransLog]", "[tblIntake]", "[IntakeID]=" &
[Forms]![frmTraceBox]![txtIntakeID])

All help is greatly appreciated.

Thanks,
FatMan


.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top