Results 1 to 4 of 4
  1. #1
    mbar is offline Novice
    Windows XP Access 2003
    Join Date
    Apr 2011
    Posts
    12

    Please help! SQL syntax error?

    Hi- have been working on this for many hours and cannot find the problem:

    I'm trying to insert a text value into a table (from another table). I need to insert the text value, then I will insert other code to email a report (not shown here), and then loop to do the same thing until the end of recordset.

    the values in the text field are ST33-1000, ST32-1015, ST32-1016, for example. When this is run, I receive a "enter parameter value" for the field ST32- which doesn't exist! ST32- is part of the actual record in the field!

    Can anyone help!?!
    Is this the right syntax?

    I've only included the relevent code. I'm trying to run the code as-is to make sure it works properly:

    Dim MyDB As Database
    Dim MyRS As Recordset
    Dim CurrentOrder As String
    Dim stSql1 As String

    Set MyDB = CurrentDb
    Set MyRS = MyDB.OpenRecordset("qryordersemailstore")
    MyRS.MoveFirst
    Do Until MyRS.EOF

    CurrentOrder = MyRS![ordernumb]

    stSql1 = "INSERT INTO tblordnumbcurrentemail (ordnumb) SELECT tblordersemailstore.ordernumb1 FROM tblordersemailstore WHERE tblordersemailstore.ordernumb1 = " & CurrentOrder & ";"

    DoCmd.RunSQL stSql1


    MyRS.MoveNext


    Loop
    End Function

  2. #2
    Robeen is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Mar 2011
    Location
    Tulsa, Oklahoma.
    Posts
    1,596
    Did this ever work?

    I've always used Insert statements with the keyword 'Values'.
    Eg:
    Code:
     
    Dim StudentName, StrSQL As String
    Me.cmbStudentName.SetFocus
    StudentName = Me.cmbStudentName.Value
    StrSQL = "INSERT INTO Table1 (StudentName) "
    StrSQL = StrSQL & "VALUES (" & "'" & StudentName & "'" & "); "
    MsgBox StrSQL
    DoCmd.RunSQL StrSQL
    I'm not certain of this - but what I would try is getting the value you need to insert into a variable as a separate operatoin - outside your Insert statement - and then using the variable in your insert statement.

    Have you changed the design of your table[s] at any point?
    I've got that parameter message in the past when I've modified a Table Design and forgotten that there are queries dependent on that Table design.
    Then Access doesn't see a field that used to exist and throws up the parameter message.

    Hope this points you in the right direction.

  3. #3
    mbar is offline Novice
    Windows XP Access 2003
    Join Date
    Apr 2011
    Posts
    12
    Worked!!!

    I was able to simplify this and used the variable as the VALUE:

    I will now include code to use "currentorder" to send individual emails with different attachments. Hopefully I won't have an more issues...

    thanks again- saved me hours!!

    Dim MyDB As Database
    Dim MyRS As Recordset
    Dim MyRS1 As Recordset
    Dim CurrentOrder As String
    Dim stSql1 As String


    Set MyDB = CurrentDb
    Set MyRS = MyDB.OpenRecordset("tblordersemailstore")
    MyRS.MoveFirst

    Do Until MyRS.EOF
    CurrentOrder = MyRS![ordernumb1]
    stSql1 = "INSERT INTO tblordnumbcurrentemail (ordnumb) "
    stSql1 = stSql1 & "VALUES (" & "'" & CurrentOrder & "'" & "); "


    Debug.Print stSql1
    MsgBox stSql1
    DoCmd.RunSQL stSql1

    MyRS.MoveNext
    Loop
    End Function

  4. #4
    Robeen is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Mar 2011
    Location
    Tulsa, Oklahoma.
    Posts
    1,596
    You're welcome!!

    I'm glad I could help.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Syntax Error
    By seth1685 in forum Access
    Replies: 3
    Last Post: 01-05-2012, 09:25 AM
  2. Compile Error Syntax Error
    By Mohamed in forum Access
    Replies: 3
    Last Post: 10-06-2011, 10:12 AM
  3. SQL Syntax Error
    By NoiCe in forum Queries
    Replies: 5
    Last Post: 04-01-2011, 11:43 AM
  4. Incomplete Syntax Clause (syntax error)
    By ajetrumpet in forum Programming
    Replies: 4
    Last Post: 09-11-2010, 10:47 AM
  5. Syntax error
    By smikkelsen in forum Access
    Replies: 6
    Last Post: 04-28-2010, 09:38 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums