Passing Where statement to a query

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi there,

I have the following code that generates an SQL statement. I am using this
with a multi-select list box.

I am trying to separate the "Where" statement that is generated and insert
it into an unbound text box, which i will then have a query reference, and
generate the results.

How can i separate the where clause?
 
oops:

Dim frm As Form
Dim ctl As Control
Dim varItem As Variant
Dim strSQL As String

Set frm = Me.Form
Set ctl = Me.lstAccreditation

strSQL = "Select [AccreditationID] from tblAccreditation where
[AccreditationID]="

For Each varItem In ctl.ItemsSelected
strSQL = strSQL & ctl.ItemData(varItem) & " OR [AccreditationID]="

Next varItem
 
Something like this...

Dim frm As Form
Dim ctl As Control
Dim varItem As Variant
Dim strSQL As String, strWHERE As String

Set frm = Me.Form
Set ctl = Me.lstAccreditation

strSQL = "Select [AccreditationID] from tblAccreditation where "

strWHERE = "[AccreditationID]="

For Each varItem In ctl.ItemsSelected
strWHERE = strWHERE & ctl.ItemData(varItem) & " OR
[AccreditationID]="

Next varItem

strSQL = strSQL & strWHERE
Me.NameOfTextbox.Value = strWHERE

--

Ken Snell
<MS ACCESS MVP>


Carlee said:
oops:

Dim frm As Form
Dim ctl As Control
Dim varItem As Variant
Dim strSQL As String

Set frm = Me.Form
Set ctl = Me.lstAccreditation

strSQL = "Select [AccreditationID] from tblAccreditation where
[AccreditationID]="

For Each varItem In ctl.ItemsSelected
strSQL = strSQL & ctl.ItemData(varItem) & " OR [AccreditationID]="

Next varItem

--
Carlee


Ken Snell (MVP) said:
What code? Not in your post....
 
Back
Top