INSERT INTO problems

  • Thread starter Thread starter ginge6000
  • Start date Start date
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
 
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
 
Back
Top