• Parameters in an SQL query (Access 2000)

    Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » Parameters in an SQL query (Access 2000)

    Author
    Topic
    #368011

    Hello,

    I am trying to run a query from under a action button and this query needs to pick up two variables (Parameters). The parameters are entered as text in two text boxes on a form. This form also is home of the button that runs the query.

    My code looks like :

    Dim SelectionSQL As String
    Dim Var1 As String
    Dim Var2 As String

    Var1 = Me.Text15
    Var2 = Me.Password

    SelectionSQL = ” SELECT tblStudent.StudentID,tblStudent.Name,tblStudent.StudentPassword FROM tblStudent WHERE (((tblStudent.Name) = “” & Var1 & “” AND ((tblStudent.StudentPassword) = “” & Var2 & “”)))”

    DoCmd.RunSQL SelectionSQL

    When I run this I keep getting the error message “Run Time Error 2343”, “A run SQL action requires an argument consisting of an SQL statement.”

    Does anybody know what I am doing wrong or why this message keeps occuring ? Any help or suggestions would be much appreciated.

    Regards,

    Viewing 2 reply threads
    Author
    Replies
    • #575507

      Taking a flyer…. shrug

      I believe you need single quotes, not double quotes, around the VAR part of your code (as you’ve declared tham as strings). (Also took out the space before SELECT, but not sure if that’ll make any difference?)So…

      SelectionSQL = “SELECT tblStudent.StudentID,tblStudent.Name,tblStudent.StudentPassword FROM tblStudent WHERE (((tblStudent.Name) = ‘” & Var1 & “‘ AND ((tblStudent.StudentPassword) = ‘” & Var2 & “‘)))”

      Hope that works

    • #575514

      Try adding a semi-colon at the end as well

      Debug.Print SelectionSQL will give you the SQL string in the Immediate window which you could try to play with in the Query SQL view window – that often shows up other problems

      HTH

    • #575530

      What is the purpose of this code? Your SQL is for a select query, so no purpose is served by trying to Run it. RunSQL is intended for an action query.

      Are you trying to find the record for that student or what?

    Viewing 2 reply threads
    Reply To: Parameters in an SQL query (Access 2000)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: