Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

INSERT INTO with a variable 1

Status
Not open for further replies.

JohnVogel

Programmer
Apr 19, 1999
117
US
I am trying to make a history file that writes the username, machinename, date of entry and the task accomplished to the HISTORY table.

Unfortunately when I try to write the string (using AR for a variable) it will ask me to supply a value for AR.
I tested it with a MsgBox to make sure there wasn't a problem with the variable, and it is fine... so what must I do to use this variable in my INSERT INTO query?


-------Example of part of my code----------------
AR = "Added " & Str$(X) & " records to schedule."
MsgBox AR, vbCritical, AR

DoCmd.RunSQL "INSERT INTO HISTORY (UserName,MachineName,DateOfEntry,Task) VALUES (fOSUserName,fOSMachineName,Now(),AR) ;"
--------------------------------------------------

John Vogel
jvogel2000@hotmail.com
 
the variable AR is being treated as text not a variable,
try this

DoCmd.RunSQL "INSERT INTO HISTORY (UserName,MachineName,DateOfEntry,Task) VALUES (fOSUserName,fOSMachineName,Now()," & AR ") ;"
 
Thank you brian... actually that didn't quite work, but it did show me how to work it :)

Here's what I used, and it seems to work perfectly... thanks again!


AR = "INSERT INTO HISTORY (UserName,MachineName,DateOfEntry,Task) VALUES (fOSUserName,fOSMachineName,Now()," & Chr$(34) & "Added " & Str$(X) & " records to schedule." & Chr$(34) & ") ;"

DoCmd.RunSQL AR


John Vogel
jvogel2000@hotmail.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top