Passing Dates and Integers in vb

teabags

Registered User.
Local time
Today, 02:00
Joined
Jun 29, 2006
Messages
21
How would I pass a string like '" & strField14 & "' as a date or an integer in an sql statement.

In otherwords is there such a function that can conver a string variable to a date
 
SQL will recognise it if you format it correctly and are using it to put data into the right field. Numbers don't need quotes, and you can use # instead of ' to force dates if you want, but this can cause localisation issues as it will attempt to get the correct date format for your region (or something like that anyway... only just managed to fix the problems caused by using # in my current project :()

But anyway, something like this
"INSERT INTO sometable(textField, NumberField, DateField) VALUES ('" & string1 & "', " & string2 & ", '" & string3 & "')"

will work, as long as string1 has text, string2 has just numbers and string3 has a date in it.
 
From personal experience I have found it easier to declare variables as long integers and passing the date value into them.
Microsoft has their own way to display dates. (i.e. 7/12/06 = 38910)
When you pass 7/12/06 into a long integer variable you will see "38910"

Your SQL Statement could be.

Dim plngDate as Date
Dim pstrSQL as String

plngDate = Cint(strField14)
pstrSQL = SELECT * FROM table WHERE Date = plngDate
 
Last edited:
look cdate on the vb help....here you can see some functions that can interest you.

checo
 

Users who are viewing this thread

Back
Top Bottom