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

INSERT INTO VALUES after button_click 1

Status
Not open for further replies.

Pampers

Technical User
Apr 7, 2004
1,300
AN
Hi Everyone,
I'm trying to figure out how to use sql in vba. I have form with two fields ConsigneeID (nummeric) and Status (text). On a buttonclick I want the two values on the form being appended to the tblStatus. So I tried this:

Code:
Private Sub Command7_Click()
Value1 = Me.ConsigneeID
Value2 = Me.Status

Dim sql As String
sql = "INSERT INTO tblSatus (ConsigneeID, Status) VALUES (Value1, Value2);"
CurrentDb.Execute (sql)
End Sub

But that is not working. How to go about this?

Pampers [afro]
There is only one way to change a diaper - fast
 
Code:
Private Sub Command7_Click()
Value1 = Me.ConsigneeID
Value2 = Me.Status

Dim sql As String
sql = "INSERT INTO tblSatus (ConsigneeID, Status) " & _
      "VALUES ('" & Value1 & "','" & Value2 & "');"
CurrentDb.Execute (sql)
End Sub
Assuming that "Value1" and "Value2" contain text. If they are numeric then remove the single quotes.

[small]On two occasions I have been asked, "Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?" I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question. (Charles Babbage)[/small]
 
Oh, that works great. Now I also understand the conconotation for the VALUES. Tnx a lot Golom. A star for you for helping me out.

Pampers [afro]
There is only one way to change a diaper - fast
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top