Need help with string formatting

maxhavoc

Registered User.
Local time
Yesterday, 23:33
Joined
Dec 12, 2005
Messages
14
Hey everyone, I need some help with formatting a string for use with the DoCmd.RunSQL() method. I can't figure out how the hell VB deals with escape characters for the purpse of variables inside strings. I have this line right now.
Code:
strSQL = "INSERT INTO OS (OS) VALUES(" + OS.Value + ")"

This is supposed to insert one row into the "OS" Table, in the "OS" field. In my form there is a textbox called "OS" and I'm trying to insert that value into the DB table.

Two things.
1) Yes, I know, I have a lot of things named "OS"
2) Yes, I know I don't need to use a string here, but I'm just presenting this is an abbreviated example, in my full program I do in fact need a string.
 
strSQL = "INSERT INTO OS (OS) VALUES('" & Me.OS & "')"
 
Hmm, ok, that works, but I guess my example wasn't perfect. What if I need to do something like:
Code:
strSQL = strSQL + '" & Serial.Value & "', "

Or, is there such thing as a "+=" operator in VB? When I try your thing in the line above, it says expected expression, I guess because it's not being inserted into an existing string, but is part of a concatenation operation.
 
just keep wrapping the quotes :)

strSQL = strSQL & "'" & Serial.Value & "', "

HTH

Peter
 

Users who are viewing this thread

Back
Top Bottom