D
DOYLE60
The code below is on the click of a command button. But I now need to make it
a module. How do I turn it into a module? And to run it from a macro, do I
use the RunCode option? Thanks.
The code below, by the way, populates a query with the choices made in a list
box on a form. The form name is "RFDialogPrintfrm". I believe this will have
to be substituted for the "Me!" below and maybe some other things. I attempted
to change it into a module but totally failed. Thanks.
Matt
__________________________________________
Private Sub Command32_Click()
Dim Q As QueryDef, db As Database
Dim Criteria As String
Dim ctl As Control
Dim Itm As Variant
Set ctl = Me![ClassOfTradeChosen]
For Each Itm In ctl.ItemsSelected
If Len(Criteria) = 0 Then
Criteria = Chr(34) & ctl.ItemData(Itm) & Chr(34)
Else
Criteria = Criteria & "," & Chr(34) & ctl.ItemData(Itm) _
& Chr(34)
End If
Next Itm
Set db = CurrentDb()
Set Q = db.QueryDefs("PrintDialogClassOfTradeLBqry")
If Len(Criteria) = 0 Then
Q.SQL = "Select * From [ClassOfTradetbl]"
Else
Q.SQL = "Select * From [ClassOfTradetbl] Where [ClassOfTrade] In(" & Criteria &
");"
End If
End Sub
__________________________________
a module. How do I turn it into a module? And to run it from a macro, do I
use the RunCode option? Thanks.
The code below, by the way, populates a query with the choices made in a list
box on a form. The form name is "RFDialogPrintfrm". I believe this will have
to be substituted for the "Me!" below and maybe some other things. I attempted
to change it into a module but totally failed. Thanks.
Matt
__________________________________________
Private Sub Command32_Click()
Dim Q As QueryDef, db As Database
Dim Criteria As String
Dim ctl As Control
Dim Itm As Variant
Set ctl = Me![ClassOfTradeChosen]
For Each Itm In ctl.ItemsSelected
If Len(Criteria) = 0 Then
Criteria = Chr(34) & ctl.ItemData(Itm) & Chr(34)
Else
Criteria = Criteria & "," & Chr(34) & ctl.ItemData(Itm) _
& Chr(34)
End If
Next Itm
Set db = CurrentDb()
Set Q = db.QueryDefs("PrintDialogClassOfTradeLBqry")
If Len(Criteria) = 0 Then
Q.SQL = "Select * From [ClassOfTradetbl]"
Else
Q.SQL = "Select * From [ClassOfTradetbl] Where [ClassOfTrade] In(" & Criteria &
");"
End If
End Sub
__________________________________