Data type mismatch in criteria

D

Database Girl

I get a error message on the following criteria string:

strCriteria = "[SAPNumber] = '" & Me!txtPO & "' AND [LineNo] = ' " &
Me!txtLine & "' AND [SunTicket] = '0'"

I know it is the LineNo that is causing the issue because when I remove it
the code works. The field on the form is a unbound text box. The properties
on the text box is set to "General Number" for format and decimal places are
set to "Auto". The "LineNo" field on the table is a primary key and is
formated with a data type of number, a field size of "Byte" and decimal
places of "Auto".

I just cannot figure out why I am getting the data type mismatch.

Your assistance would be appreciated.
 
D

Douglas J. Steele

Bytes are numeric fields, not text.

Remove the single quotes on either side of Me!txtLine
 
P

Paul Shapiro

The SQL is executed against the table. Since the table defines lineNo as a
byte, the sql has to treat it as a number. Basically, remove the single
quotes around the line number value:

strCriteria = "[SAPNumber] = '" & Me!txtPO & "' AND [LineNo] = " &
Me!txtLine.Value & " AND [SunTicket] = '0'"

Access automatically converts the string value of the textbox to a number,
or you can make an explicit conversion:

strCriteria = "[SAPNumber] = '" & Me!txtPO & "' AND [LineNo] = " &
CByte(Me!txtLine.Value) & " AND [SunTicket] = '0'"
 
D

Database Girl

Opps. You are right. I works like a charm now. Thanks for you help.

Douglas J. Steele said:
Bytes are numeric fields, not text.

Remove the single quotes on either side of Me!txtLine

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Database Girl said:
I get a error message on the following criteria string:

strCriteria = "[SAPNumber] = '" & Me!txtPO & "' AND [LineNo] = ' " &
Me!txtLine & "' AND [SunTicket] = '0'"

I know it is the LineNo that is causing the issue because when I remove it
the code works. The field on the form is a unbound text box. The
properties
on the text box is set to "General Number" for format and decimal places
are
set to "Auto". The "LineNo" field on the table is a primary key and is
formated with a data type of number, a field size of "Byte" and decimal
places of "Auto".

I just cannot figure out why I am getting the data type mismatch.

Your assistance would be appreciated.
 

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