input box to capture number as text for sql

msyth2

Registered User.
Local time
Yesterday, 23:39
Joined
Dec 15, 2010
Messages
12
I have code like this

Dim Mon as string
Mon = Inputbox ("Month","Month")

sQL = .... & _
"Where Month = " Mon


If I enter 05 in input box, it always caputure number value and sql has error, because in the table filed "Month" is text "05".

How can i make it capture text? I tried use str() in sql but it had error...

Thanks a lot.


Edit:
I think in the sql statement the input will show 05 there, but the error still says "data type dismathc in critiria expression". In table the month column is "Text", I wonder if String is different from Text?
 
Last edited:
Re: input box to capture nubmer as text for sql

Try

sQL = .... & _
"Where Month = '" Mon & "'"
 
Re: input box to capture nubmer as text for sql

ty very much. i thought it would work too... but now in the error displaying sql statement, it's like '05' ... it doesn't make sence.
 
Re: input box to capture nubmer as text for sql

Try

sQL = .... & _
"Where Month = '" Mon & "'"

How about one more ampersand and square brackets because of the Access Reserved Word?

"Where [Month] = '" & Mon & "'"
 
Are you building the sql in code or is it in a query?
 
The actual column name is "FM" rather than Month, but I do see bob's point. I went ahead and tried '05' again it worked this time... Maybe because I cleaned out the table name in table.column.

Thank you all for your help.
 
The extra & that Bob pointed out (and I missed) was important. Presumably you added that in.
 

Users who are viewing this thread

Back
Top Bottom