INSERT INTO problems

G

ginge6000

Hi all,

I hope this doesn't appear twice, I did it a while ago and it never
came up! So here goes again!

I am trying to use INSERT INTO to insert one record in to a table (tna
feedback) in two fields (USER ID: and DESK/LAPTOP).

The values are generated by two different forms; stUser comes from
this form and stMachine comes from another form which has been hidden
once the user has chosen the value. This part works fine.

However, every time I run it I get an "Incomplete Query clause" error
message but can't fidure out what I've done wrong!

Here is the code:

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

I realise that the table and field names are not ideal but someone
else set up the database and to change these would require changing
every single query in the database!!!

Please help me, this is baffling me!

Ben
 
R

rwr

Hi all,

I hope this doesn't appear twice, I did it a while ago and it never
came up! So here goes again!

I am trying to use INSERT INTO to insert one record in to a table (tna
feedback) in two fields (USER ID: and DESK/LAPTOP).

The values are generated by two different forms; stUser comes from
this form and stMachine comes from another form which has been hidden
once the user has chosen the value. This part works fine.

However, every time I run it I get an "Incomplete Query clause" error
message but can't fidure out what I've done wrong!

Here is the code:

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

I realise that the table and field names are not ideal but someone
else set up the database and to change these would require changing
every single query in the database!!!

Please help me, this is baffling me!

Ben

Look at Rick Brandt's post. You have single quotes that are not needed
after INTO and Before ([User.

Ron
 

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
SQL question marks 3
FindFirst Criteria Problem 1
INSERT INTO 2
Something wrong with my code. 1
INSERT INTO Part 2 2
help with insert into statement 2

Top