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

insert sql wih autonumber , HELP!

Status
Not open for further replies.

Bullsandbears123

Technical User
Feb 12, 2003
291
US
I have a sub, that inserts sql values into my table, the table has an autonumber and I'm not sure how to insert values with an autonumber. I keep getting a syntax error.
The table has id,txndate,txncode,synbol, etc. etc.
but the autonumber is the "ID" field. Please help. What is wrong with my code?




Private Sub btn_submit_Click()

Dim mysql
Dim strid As String
Dim strtxndate As String
Dim strtxncode As String
Dim strsymbol As String
Dim strprice As String
Dim strcommission As String
Dim strquantity As String
Dim strbroker As String



strid = "1"
strtxndate = "1"
strtxncode = "2"
strsymbol = "3"
strprice = "4"
strcommission = "5"
strquantity = "6"
strbroker = "7"



mysql = "INSERT [txndate], [txncode],[symbol], [price], [commission_per_share], [quantity], [broker] into tbl_trade_orders values(" & strtxndate & "," & strtxncode & "," & strsymbol & "," & strprice & "," & strcommission & "," & strquantity & "," & strbroker & ");"
CurrentDb.Execute mysql
 
So that others know what the problem is and how to fix it, I think I will refer to the following thread that was having the same problem as you. It just posted and was resolved:

thread701-814305

Had to do with the need to insert single quotes in the overall string being built for the SQL execute statement. (See red single quotes)

Code:
mysql = "INSERT [txndate], [txncode],[symbol], [price], [commission_per_share], [quantity], [broker] into tbl_trade_orders values([red]'[/red]" & strtxndate & "[red]'[/red],[red]'[/red]" & strtxncode & "[red]'[/red],[red]'[/red]" & strsymbol & "[red]'[/red],[red]'[/red]" & strprice & "[red]'[/red],[red]'[/red]" & strcommission & "[red]'[/red],[red]'[/red]" & strquantity & "[red]'[/red],[red]'[/red]" & strbroker & "[red]'[/red]);"

Good luck with your project.

Bob Scriver
[blue]Want the best answers? See FAQ181-2886[/blue]


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top