Results 1 to 4 of 4
  1. #1
    New Lounger
    Join Date
    Nov 2001
    Location
    Northwich, Cheshire UK
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Parameters in an SQL query (Access 2000)

    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.St udentPassword 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,

  2. #2
    New Lounger
    Join Date
    Nov 2001
    Location
    Twickenham, UK
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Parameters in an SQL query (Access 2000)

    Taking a flyer.... <img src=/S/shrug.gif border=0 alt=shrug width=39 height=15>

    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.St udentPassword FROM tblStudent WHERE (((tblStudent.Name) = '" & Var1 & "' AND ((tblStudent.StudentPassword) = '" & Var2 & "')))"

    Hope that works

  3. #3
    4 Star Lounger SteveH's Avatar
    Join Date
    Jan 2001
    Location
    Chelsea, Gtr London, United Kingdom
    Posts
    587
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Parameters in an SQL query (Access 2000)

    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
    Steve H
    IT Lecturer/Access Developer
    O2K SR3/O2010; Win7Pro

  4. #4
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Parameters in an SQL query (Access 2000)

    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?
    Charlotte

Posting Permissions

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