Error 3134

echo0001

Registered User.
Local time
Today, 15:40
Joined
Aug 30, 2008
Messages
55
Hello,

I have the following code and cannot get it to work i have been at it for hours and im getting the error 3134, Syntax Error in INSERT INTO Statement.

Any help would be great


Code:
Private Sub Command20_Click()

Dim mySQL As String
Dim rs As dao.Recordset

Set rs = CurrentDb.OpenRecordset("Select [Admins].[Name_] From [Admins] Where [Pin_] = '" & Me![Text2] & "';", dbOpenSnapshot)

With rs
     If .RecordCount <> 0 Then
     
     mySQL = "INSERT INTO Access Histroy (Date_, Time_, Name_)"
     mySQL = mySQL & "SELECT Date() AS Date_, Time() AS Time_, Name_ AS Name_"
     mySQL = mySQL & "FROM Admins"
     mySQL = mySQL & "Where [Pin_] = '" & Me![Text2] & "'"
     DoCmd.SetWarnings False
     DoCmd.RunSQL mySQL
     DoCmd.SetWarnings True
     
     
     Else
         
     End If
End With

Set rs = Nothing

End Sub
 
Put a

Debug.MySQL

in the code just before the Docmd code to show in the immediate window what your SQL string looks like. I can see you'll be missing a bunch of spaces that will be needed because you have not included them in your code.
 
am i being stupid here but i did what you said and i get a compile error, Expected: Print or ? or Assert
 
That was just a little typo.

Debug.Print mySQL

and look in the Immediate Window.
 
ok got that, found the missing spaces and sorted that but still getting same error
 
sorted now, forgot the simple [] around the table name
 
Glad to hear!

See why you should always avoid naming objects reserved keywords? ;)
 
Hello i have yet again came across the same error, i think i just need a fresh set of eyes

Code:
Private Sub Command14_Click()

Dim mySQL0 As String

    mySQL0 = " INSERT INTO [Check In/Out] (Childs Name, Check In, Date01) "
    mySQL0 = mySQL0 & " SET Childs Name AS Childs Name, Time() AS Check In, Date() AS Date01 "
    mySQL0 = mySQL0 & " FROM Members "
    mySQL0 = mySQL0 & " Where Childs Name = '" & Me![Combo12] & "' "
    
Debug.Print mySQL0
DoCmd.SetWarnings False
DoCmd.RunSQL mySQL0
DoCmd.SetWarnings True

End Sub
 
I can see it already but since you're not following good naming conventions you would have to enclose all your table names and field names in square brackets from this point forward :)
 
Where which naming conventions as far as i am aware im not
 
The corrected SQL is this:
Code:
[COLOR=silver]   mySQL0 = "[B]SELECT[/B]([B][[/B]Childs Name[B]][/B] , Time() As [Check In], Date() As Date01"[/COLOR]
[COLOR=silver]   [B]mySQL0 = mySQL0 & " INTO [Check In/Out][/B][/COLOR]
[COLOR=silver]   mySQL0 = mySQL0 & " FROM Members "[/COLOR]
[COLOR=silver]   mySQL0 = mySQL0 & " Where [B][[/B]Childs Name[B]][/B] = '" & Me.Combo12 & "'[B])[/B]"[/COLOR]

Wrong SQL- see next post.


And if you don't use spaces or special characters in your field or object names, it could be done without the square brackets.
 
Last edited:
Oops, nevermind - it would be this with an append query, sorry - I got thinking it could be a make table query.

Code:
    mySQL0 = "INSERT INTO ([Check In/Out] ([B][COLOR=red][[/COLOR][/B]Childs Name[COLOR=black][B][COLOR=red]][/COLOR][/B][COLOR=black], [/COLOR][COLOR=red][B][[/B][COLOR=black]Check In[/COLOR][B]][/B][/COLOR][COLOR=black], Date01) [/COLOR]"[/COLOR]
    mySQL0 = mySQL0 & " [B][COLOR=red]SELECT [/COLOR][/B][B][COLOR=red][[/COLOR][/B]Childs Name[B][COLOR=red]][/COLOR][/B] , Time() [COLOR=black]As [B][COLOR=red][[/COLOR][/B]Check In[/COLOR][COLOR=red][B]][/B][/COLOR], Date() As Date01"
    mySQL0 = mySQL0 & " FROM Members "
    mySQL0 = mySQL0 & " Where [B][COLOR=red][[/COLOR][/B]Childs Name[B][COLOR=red]][/COLOR][/B] = '" & Me.Combo12 & "'"
 

Users who are viewing this thread

Back
Top Bottom