"invalid sql statement expected 'delete' 'insert'" (Query Problem)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Heero Stone
    New Member
    • Aug 2011
    • 2

    "invalid sql statement expected 'delete' 'insert'" (Query Problem)

    my code is having an error "invalid sql statement expected 'delete' 'insert'"

    Here's my code;

    Code:
    Sub GetMyData()
    Dim cnn As ADODB.Connection
    Dim rs As ADODB.Recordset
    Dim sQRY As String
    Dim strFilePath As String
    
        strFilePath = "C:\Document\Parkside.mdb"
        Set cnn = New ADODB.Connection
        Set rs = New ADODB.Recordset
        Sheet2.Range("A1").ClearContents
        cnn.Open "Provider=Microsoft.ACE.OLEDB.12.0;" & _
            "Data Source=" & strFilePath & ";"
        sQRY = "Beam Forces"
        rs.CursorLocation = adUseClient
        rs.Open sQRY, cnn, adOpenStatic, adLockReadOnly
        Application.ScreenUpdating = False
        Sheet2.Range("B2").CopyFromRecordset rs
        rs.Close
        Set rs = Nothing
        cnn.Close
        Set cnn = Nothing
        Exit Sub
    End Sub
    I did a search on the internet regarding this and found-out that the error had something to do with the query

    Code:
    sQRY = "Beam Forces"
    so I change it to

    Code:
    sQRY = "SELECT * FROM Beam Forces"
    based on the suggested syntax on the internet.

    Now, when I run the code again its having a different error now "The microsoft office access database engine cannot find the input table or query 'Beam'. Make sure it exists and that its name is spelled correctly."

    The thing is theres a Table 'Beam Forces' in the access file. Would it be possible the code doesn't recognize 2 worded query?

    Could anyone help me on this? Thanks :)
    Last edited by NeoPa; Aug 11 '11, 01:56 PM. Reason: CODE tags not optional - added for you this time
  • Dody
    New Member
    • Aug 2011
    • 11

    #2
    I think you must put table name in prackets [] if it consist of more than word

    try this statment
    Code:
    sQRY = "SELECT * FROM [Beam Forces]"
    I wish it work :)

    Comment

    • Heero Stone
      New Member
      • Aug 2011
      • 2

      #3
      Thanks Dody! It worked!

      Never thought of using the bracket! I tried using parenthesis thou.

      Thanks again :)

      Comment

      Working...