INSERT INTO problems

G

ginge6000

Hi,

I am trying to insert to values into two different fields (USER ID:
and DESK/LAPTOP) in a table (tna feedback). The values come from
forms. I've done this previously and for some reason I can't get it
to work right this time!

Dim SQL As String
Dim stUser As String
Dim stMachine As String
Dim stTable As String



If IsNull(Me.DESK_LAPTOP) Or (Me.DESK_LAPTOP) = "" Then
If 1 = MsgBox("Please enter User ID and Laptop/Desktop into
TNA form", vbOKOnly, "Missing Data!") Then

User_id.SetFocus
stUser = Me.User_id.Text

DoCmd.OpenForm "Frm:TNA_Feedback", , , , , acDialog

stMachine = [Forms]![Frm:TNA_Feedback]![Text3]

stTable = "tna feedback"

SQL = "INSERT INTO'" & stTable & "'(USER ID:, DESK/LAPTOP)
VALUES ('" & stUser & "','" & stMachine & "');"

DoCmd.RunSQL SQL

DoCmd.Close acForm, "Frm:TNA_Feedback"

GoTo Exit_Command25_Click

End If
End If

Every time I run it I get an "Incomplete Query Clause" error message.
What am I doing wrong!

I realise that the table name and field names aren't ideal but someone
else set up the database and to change them would invlove changing a
lot of related queries etc.!

Please help!

Ben
 
R

Rick Brandt

Hi,

I am trying to insert to values into two different fields (USER ID: [snip]
SQL = "INSERT INTO'" & stTable & "'(USER ID:, DESK/LAPTOP)
VALUES ('" & stUser & "','" & stMachine & "');"
[snip]

There is no space between INTO and the Table Name.

The Table Name should not have quotes around it.

Field names with spaces or "funny" characters need square brackets around them.

Your VALUES clause looks okay to me.

SQL = "INSERT INTO " & stTable & " ([USER ID:], [DESK/LAPTOP]) VALUES ('" &
stUser & "','" & stMachine & "');"
 

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

Similar Threads

INSERT INTO problems 1
Insert data into Combo 2
Something wrong with my code. 1
INSERT INTO Part 2 2
INSERT INTO 2
SQL question marks 3
help with insert into statement 2
Runtime ERROR 3134 2

Top