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

INSERT INTO using a variable / syntax error 2

Status
Not open for further replies.

swtrader

IS-IT--Management
Dec 23, 2004
182
US


I get an "Object Required" error on the following code --

Have tried numerous alternatives -- nothing works. Am just trying to learn how to insert a variable into the table... ?? Thanks.

very new to VBA

=====================
...... this is in a module

Private Sub PutTheValueIntoTheTable()

Dim mySQL As String
Dim TestThingy

TestThingy = "This is the test data -- one more time."

'MsgBox " " & TestThingy

mySQL = "INSERT INTO tblTestTable (TestTextData) VALUES ('" & TestThingy.Value & "')"

DoCmd.RunSQL mySQL

End Sub
 
You don't need the .Value property.
Just use
Code:
 "INSERT INTO tblTestTable (TestTextData) VALUES ('" & TestThingy & "')"
Also, you should give the variable TestThingy a data type like
Dim TestThingy As String

rather than let it default to a Variant type.
 
That did it! wasted a couple of hours on that one. Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top