By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,778 Members | 1,318 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,778 IT Pros & Developers. It's quick & easy.

insert sql command in access

P: 46
how do i code an insert record command on the back end of access (using vb).
my code for my add record button is:

"Insert into tableViama " & _
"(v1,v2)"& _
values"(Txtv1, Txtv2)"


this is not working.
Mar 21 '07 #1
Share this Question
Share on Google+
2 Replies


Rabbit
Expert Mod 10K+
P: 12,366
how do i code an insert record command on the back end of access (using vb).
my code for my add record button is:

"Insert into tableViama " & _
"(v1,v2)"& _
values"(Txtv1, Txtv2)"


this is not working.
This is a SQL statement, not code. And an incorrectly syntaxed SQL statement at that.

Assuming that Txtv1 and Txtv2 are controls on your form:
Expand|Select|Wrap|Line Numbers
  1. DoCmd.RunSQL "INSERT INTO tableViama (v1, v2) VALUES ('" & _
  2.   Txtv1 & "', '" & Txtv2 & "')"
Mar 21 '07 #2

NeoPa
Expert Mod 15k+
P: 31,489
What this is doing is formulating a string in the VBA code, then passing that string to the SQL engine using DoCmd.RunSQL. Two separate steps that should be considered distinct. If it helps to understand, use a string variable (EG. strSQL) to formulate the string, then call :
Expand|Select|Wrap|Line Numbers
  1. DoCmd.runSQL strSQL
Mar 23 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.