strsql

  • Thread starter hotrod1952 via AccessMonster.com
  • Start date
H

hotrod1952 via AccessMonster.com

I am trying to set-up a command button on a form to take data in two unbound
textboxes and store them into a table. The following is my code from the
click event. I must have a syntax error or ?

Dim strSQL As String
strSQL = "INSERT INTO Program1 (opcode,sp) " & "VALUES (" & me.cboOpcode1
& ", " me.TxtSp1 & ");"


DoCmd.RunSQL

What am i missing?
 
D

Dirk Goldgar

hotrod1952 via AccessMonster.com said:
I am trying to set-up a command button on a form to take data in two
unbound
textboxes and store them into a table. The following is my code from the
click event. I must have a syntax error or ?

Dim strSQL As String
strSQL = "INSERT INTO Program1 (opcode,sp) " & "VALUES (" &
me.cboOpcode1
& ", " me.TxtSp1 & ");"


DoCmd.RunSQL

What am i missing?


You're missing an '&' before me.TxtSp1:

strSQL = _
"INSERT INTO Program1 (opcode,sp) " & _
"VALUES (" & Me.cboOpcode1 & ", " & Me.TxtSp1 & ");"

Also, if either of these fields is a text field, you'll need to embed quotes
around the values. For example, if they're both text fields, but neither
will contain the single-quote character ('), you'd need:

strSQL = _
"INSERT INTO Program1 (opcode,sp) " & _
"VALUES ('" & Me.cboOpcode1 & "', '" & Me.TxtSp1 & "');"
 
F

franky

Try this. I think you may have forgotten the apostrophe (') in the sql
statement for each value:

strSQL = "INSERT INTO Program1 (opcode,sp) " & "VALUES ('" & me.cboOpcode1
& "', '" me.TxtSp1 & "');"
 
F

franky

Also noticed you forgot an "&" in your last value. The apostrophe is
required if your inserting into a text field.

strSQL = "INSERT INTO Program1 (opcode,sp) " & "VALUES ('" & me.cboOpcode1
& "', '" & me.TxtSp1 & "');"
 
H

hotrod1952 via AccessMonster.com

Thanks for your help guys.
I think I got the apostraphe's and I see where I missed the & sign.
here is my corrected code:

Dim strSQL As String
strSQL = "INSERT INTO Program1 (opcode,sp) " & "VALUES ('" & Me.
cboOpCode1 & "', '" & Me.TxtSP1 & "')"
DoCmd.RunSQL

When I run the code I get Compile error Argument not optional.
Using Access 97 (company is too cheap to upgrade).
Try this. I think you may have forgotten the apostrophe (') in the sql
statement for each value:

strSQL = "INSERT INTO Program1 (opcode,sp) " & "VALUES ('" & me.cboOpcode1
& "', '" me.TxtSp1 & "');"
I am trying to set-up a command button on a form to take data in two unbound
textboxes and store them into a table. The following is my code from the
[quoted text clipped - 8 lines]
What am i missing?
 
D

Dirk Goldgar

hotrod1952 via AccessMonster.com said:
Thanks for your help guys.
I think I got the apostraphe's and I see where I missed the & sign.
here is my corrected code:

Dim strSQL As String
strSQL = "INSERT INTO Program1 (opcode,sp) " & "VALUES ('" & Me.
cboOpCode1 & "', '" & Me.TxtSP1 & "')"
DoCmd.RunSQL

When I run the code I get Compile error Argument not optional.
Using Access 97 (company is too cheap to upgrade).


Hah, I didn't even notice that you hadn't passed strSQL to the RunSQL
method, or else maybe I just assumed you didn't bother typing it into your
message. This:
DoCmd.RunSQL

.... needs to be this:

DoCmd.RunSQL strSQL
 
H

hotrod1952 via AccessMonster.com

I am being dumb today.

Here was my solution:
DoCmd.RunSql strSql
Again thanks for your help guys.
Thanks for your help guys.
I think I got the apostraphe's and I see where I missed the & sign.
here is my corrected code:

Dim strSQL As String
strSQL = "INSERT INTO Program1 (opcode,sp) " & "VALUES ('" & Me.
cboOpCode1 & "', '" & Me.TxtSP1 & "')"
DoCmd.RunSQL

When I run the code I get Compile error Argument not optional.
Using Access 97 (company is too cheap to upgrade).
Try this. I think you may have forgotten the apostrophe (') in the sql
statement for each value:
[quoted text clipped - 7 lines]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top