Results 1 to 4 of 4

Thread: syntax error

  1. #1
    Join Date
    May 2002
    Posts
    395

    Unanswered: syntax error

    I received a syntax error on this SQL statement
    "SELECT * FROM tblRGAmo;"
    I just can't see what is wrong with it.

    ' Procedure calls for CreateChart
    Private Sub cmdOpenQtrChart_Click()
    CreateChart
    End Sub


    Private Sub CreateChart()
    Dim DB As Database

    Set DB = CurrentDb()
    sqlstate = "SELECT * FROM tblRGAmo;"
    DoCmd.OpenForm "Form1", , , sqlstate

    End Sub

    Thanks!!

  2. #2
    Join Date
    Feb 2002
    Posts
    403
    Private Sub CreateChart()
    Dim DB As Database
    Dim sqlState as String

    Set DB = CurrentDb()
    sqlstate = "SELECT * FROM tblRGAmo;"
    DoCmd.OpenForm "Form1", , , sqlstate

    End Sub

  3. #3
    Join Date
    Oct 2002
    Location
    Rochester, NY
    Posts
    84
    Originally posted by dynamictiger
    Private Sub CreateChart()
    Dim DB As Database
    Dim sqlState as String

    Set DB = CurrentDb()
    sqlstate = "SELECT * FROM tblRGAmo;"
    DoCmd.OpenForm "Form1", , , sqlstate

    End Sub
    I'm not positive, but I believe the semicolon on your sqlstate is causing the problem. Dynamictiger also makes a good point that your variable names should be explicitly declared and typed. It can save you hours of troubleshooting at a later date. You can remind yourself to develop this good habit by always putting the following line as the first or second line in each module you develop (including Forms!)

    Option Explicit

    If you do this, when you compile, any undeclared variables will be reported as errors. This will save you though, trust me! If you mistype a variable name, the problem will be evident at compile time and you won't have to single step through all of your code to find out why some variable is behaving well in your app.
    Regards,
    Terry

  4. #4
    Join Date
    Aug 2002
    Location
    Québec, Canada
    Posts
    109
    I believe the error is in the openform, you are passing an argument in the wrong parameters, try this code:

    Code:
    Private Sub CreateChart()
    
        Dim DB As Database
        Dim sqlstate As String
        Set DB = CurrentDb()
        sqlstate = "SELECT * FROM tblRGAmo;"
        DoCmd.OpenForm "Form1", , , , , , sqlstate
    
    End Sub
    JefB

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •