Dynamic Combobox Value Cause SQL String to MisMatch

  • Thread starter Thread starter CornDog
  • Start date Start date
C

CornDog

I have a Comobox that can look up any type of variable
from any table. This value is passed to a SQL statement to
be used as a filter criteria.

If its a string it works fine. But DATES and CURRENCIES
screw up because of type mismatch. Is there some easy way
to identify a string as fitting a DATE format(or type) or
a string as being of CURRENCIE format(or type).

For exampel something like this:

IsDate("Mickey Mantle") returns False
IsDate("08/08/01") returns True
IsDate("Febuary 08, 2001") returns True
IsCurrency("Febuary 08, 2001") returns False
IsCurrency("$1.00") returns True

Casue then I can modify the SQL statement based on the
boolean result.
 
Hi,

Have you tried using the CStr function to convert the
value to a string before adding it to your SQL statement?

Something like this...

dim mySQL as string
mySQL = "select * from [tablename] where [fieldname] = " &
Cstr(myComboBox.value)

The only problme with this is that if there isn't any data
in the combo box using the cStr function will return
an "invalid use of null" error.

Hope that helps.
Rebecca
 
Actually, come to think of it, my suggestion for using
cStr won't work with a date value because you have to put
a date value inside # marks within an SQL statement. You
probably should:

1) test the value from the combo box for content (using
the isdate function or iscurrency functions)
2) put the value from your combo box into a string
variable, surrounding it with # makrs if it's a date value

I'm not aware of any separator character required when
evaluating currency values within an SQL statement, so
that part is a mystery.

Good Luck!
Rebecca
 
Back
Top