In addition to the point that 'PC Datasheet' makes elsewhere in this thread
about the data type of the 'strLocation' variable, you have the name of the
variable inside the quotes delimiting the SQL string. That will result in
adding the *name* of the variable, the literal text 'strLocation' into the
string instead of the *value* stored in the variable. You need something
like ...
" ... [VehicleNumber], " & strLocation & ", ... "
.... if the value is a number or ...
"...[VehicleNumber], '" & strLocation & "', ..."
.... if the value is a string.
In the second example, that's a single quote followed by a double quote
before the first ampersand, and a double qote followed by a single quote
after the second ampersand.
A useful technique for debugging this type of problem is to assign the SQL
statement to a string and Debug.Print the result the Immediate window, so
you can see what the finished string looks like, e.g. ...
strSQL = <build your SQL statement here>
Debug.Print strSQL
--
Brendan Reynolds (MVP)
http://brenreyn.blogspot.com
The spammers and script-kiddies have succeeded in making it impossible for
me to use a real e-mail address in public newsgroups. E-mail replies to
this post will be deleted without being read. Any e-mail claiming to be
from brenreyn at indigo dot ie that is not digitally signed by me with a
GlobalSign digital certificate is a forgery and should be deleted without
being read. Follow-up questions should in general be posted to the
newsgroup, but if you have a good reason to send me e-mail, you'll find
a useable e-mail address at the URL above.
Paul B. said:
I have the following code which when run prompts to the value of
'strLocation'. Can someone tell me what I am missing. Thank you in
advance.....
-------------------
Dim strLocation As Integer
strLocation = Left(Me!AssignedTo, 3)
DoCmd.RunSQL "INSERT INTO tblVehicles(VehicleStatus, VehicleNumber,
Location, Disposition) VALUES('In Service', [VehicleNumber], strLocation,
[AssignedTo])"
---------------------
The value of strLocation is correctly assigned, but I am still prompted to
enter it.
Cheers