Multiple Select & SQL String

Results 1 to 4 of 4

Thread: Multiple Select & SQL String

  1. #1
    BuhBuh Guest

    Default Multiple Select & SQL String

    Hi. Here is what I want to do:<BR>- I have a Multiple Select Box containing all the US.States, so the user can chose all the states he wants. <BR><BR>- When he submit the form, I need to built an SQL String to get all the records in the database (access) corresponding to his choices.<BR><BR>Ex: The user wants to sort all the clients who are living Texas and New York...<BR><BR>My big problem is that I don&#039;t know how many States the user will select and It&#039;s a real nightmare for me to built my SQL String depending of the user choices. I will appreciate some help from you all! Thanks a lot

  2. #2
    el gano Guest

    Default RE: Multiple Select & SQL String

    The SQL should be the easy part. Just put your form data into variables then add them to the statement.<BR><BR>mySQL = "SELECT * FROM MyTable WHERE BLA BLA BLA"<BR>iF &#039;some criteria<BR>mySQL = mySQL & " AND State=&#039;" & var1 & "&#039;"<BR>end if<BR><BR>iF &#039;some criteria<BR>mySQL = mySQL & " AND State=&#039;" & var1 & "&#039;"<BR>end if

  3. #3
    Eddie Campbell Guest

    Default RE: Multiple Select & SQL String

    Assumimg that your list box is called States, and that the values are the state abbreviations, try this<BR><BR>WhereClause = "Where State In("<BR>For each item in Request.Form("States")<BR> WhereClause = WhereClause & item & ","<BR>Next<BR>WhereClause = Left(WhereClause,Len(WhereClause)-1) & ")"<BR>Sql = "Select * from TblStates " & WhereClause

  4. #4
    BuhBuh Guest

    Default RE: Multiple Select & SQL String

    Thanks a lot buddy...It was what I needed! :)

Posting Permissions

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