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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

insert statement

Status
Not open for further replies.

VBVines

MIS
Jun 11, 1999
98
US
I have what I thought was a very simple sql statement. I have text boxes and combo boxes. The values entered are going into variables (val1 -- val4). I do a debug.print and I see that the variables are indeed holding the values that I put in but when I go to do this sql statement I get "val1 cannot be used in this way. it must be a constaint or a variable." Isn't this the corret syntaxl for the insert statement. Keep in mind I have exactly this all on one line. val1 and val3 are dimmed as integers,where val2 and val4 are strings
mysql = "Insert into mail(NameID,Description,SubscriptionID,DateReceived) values(val1,val2,val3,val4)" aspvbwannab
 
Try this instead

mysql = "Insert into mail(NameID,Description,SubscriptionID,DateReceived) values(" & val1 & ",'" & val2 & "'," & val3 & ",'" & val4 & "')" Mark

The key to immortality is to make a big impression in this life!!
 
What you are doing trying to add a record with the name of the variables as the value for the fields. So right now you are saying that NameID=val1. What you want is NameID=value of val1. So replace you code with :

mysql = "Insert into mail(NameID,Description,SubscriptionID,DateReceived) values(" & val1 & ",'" & val2 & "'," & val3 & ",'" & val4 & "')"

This should work a lot better (I presume that Description is a string, and DateReceived is a date).

Good luck with it,

Heico
 
You guys are both awesome thank you very much. man does not live by msdn alone. I would be scratching my head alot more if not for this website and folks like you. Thanks again. You both gave me the same thing. aspvbwannab
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top