G
Guest
I'm trying to create a string of values from a list box and pass this to the
WHERE condition to open a report.
I've tried code given in previous posted answers, but when adapting it to my
own DB, I'm going wrong somewhere.
Dim frm As Form, ctl As Control
Dim varItem As Variant
Dim strSQL As String
Set frm = Forms!frmMatchRestoFund
Set ctl = frm!PrintList
strSQL = "[FunderProgramme]="
For Each varItem In ctl.ItemsSelected
strSQL = strSQL & ctl.ItemData(varItem) & " OR [FunderProgramme]="
Next varItem
strSQL = Left$(strSQL, Len(strSQL) - 22)
DoCmd.OpenReport "rptFunder1", acViewPreview, , "([strSQL])"
The problems:
1) The example I took this from had to truncate 12 characters off the string
as it was " OR [EmpID]=". If I change this to 22 because my code adds " OR
[FunderProgramme]=" I get an error message "invalid call or procedure".
2) If I leave the truncate as "strSQL = Left$(strSQL, Len(strSQL) - 12), I
get a message box asking me for the value of "strSQL".
Any pointers gratefully received.
thanks
Winger
WHERE condition to open a report.
I've tried code given in previous posted answers, but when adapting it to my
own DB, I'm going wrong somewhere.
Dim frm As Form, ctl As Control
Dim varItem As Variant
Dim strSQL As String
Set frm = Forms!frmMatchRestoFund
Set ctl = frm!PrintList
strSQL = "[FunderProgramme]="
For Each varItem In ctl.ItemsSelected
strSQL = strSQL & ctl.ItemData(varItem) & " OR [FunderProgramme]="
Next varItem
strSQL = Left$(strSQL, Len(strSQL) - 22)
DoCmd.OpenReport "rptFunder1", acViewPreview, , "([strSQL])"
The problems:
1) The example I took this from had to truncate 12 characters off the string
as it was " OR [EmpID]=". If I change this to 22 because my code adds " OR
[FunderProgramme]=" I get an error message "invalid call or procedure".
2) If I leave the truncate as "strSQL = Left$(strSQL, Len(strSQL) - 12), I
get a message box asking me for the value of "strSQL".
Any pointers gratefully received.
thanks
Winger