SQL with variable from form

  • Thread starter Thread starter info
  • Start date Start date
I

info

Hi,

I should like to use the following code by opening of a report.

sql = "AREA in (" & "'501'" & "," & "'502'" & ","
& "'503'" & "," & "'133'" & "," & "'134'" & ")"

Only with the 501, 502, 503, 133 and 134 from out a combobox from the form.
Area 1 up to and including 5, but it seems not to be working by me?

Frank
 
I am not sure how you are getting multiple values back from a combo box or are you using multiple combo boxes? If you want multiple values to be selected you are better off using a multi-select (extended) list box

Having got the values & created the SQL what are you doing with it? you can apply it as a Filter to the form. eg
Me.Filter = sq
Me.FilterOn = Tru

To use a list box you would have to include code to check whether any selection has been made and if so build the sq

e
Dim vItm as varian

sql="
Select case lst.ItemsSelect.Coun
Case
Msgbox "No selection...
Exit su
Case
sql="[Area] = '" &me.ls
Case els
sql="
for each vItm in me.lst.ItemsSelecte
if slq="" the
sql=me.lst.column(0,vitm
els
sql=sql &"," &me.lst.column(0,vitm
end i
Nex
sql="[Area] in (" &sql &")
end selec
me.filter=sq
me.filteron = tru

If the values are coming from another form you will not be able to use the ME keyword, use FORMS(<FormName>) instead of M

On calling the second form pass the name of the calling form as a parameter and use the OPENARGS to get the form name e
To Open the Select form
DoCmd.OpenForm "frmSelect",,,,,,Me.Nam
In the Select Form us
FORMS(Me.OpenArgs
to refer to the calling for

HT
Terr
----- info wrote: ----

Hi

I should like to use the following code by opening of a report

sql = "AREA in (" & "'501'" & "," & "'502'" & ",
& "'503'" & "," & "'133'" & "," & "'134'" & ")

Only with the 501, 502, 503, 133 and 134 from out a combobox from the form
Area 1 up to and including 5, but it seems not to be working by me

Fran
 
Back
Top