Good question! I have 20 CheckBoxes on a Form, bound to a Table. I want to
be able to click on a few CheckBoxes, say 'Continental', 'Jet Blue', 'Delta',
and 'Southwest', and add those elements to a Query. I have this macro now:
Private Sub CallQuery_Click()
Dim strClass As String
Dim strGroup As String
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim strSQL As String
Set db = CurrentDb
Set qdf = db.QueryDefs("qrySummary")
' Close the query if it is already open
If SysCmd(acSysCmdGetObjectState, acQuery, "qrySummary") =
acObjStateOpen Then
DoCmd.Close acQuery, "qrySummary"
End If
' Get the values from the combo boxes
If IsNull(Me.cboClass.Value) Then
strClass = " Like '*' "
Else
strClass = "='" & Me.cboClass.Value & "' "
End If
If IsNull(Me.cboGroup.Value) Then
strGroup = " Like '*' "
Else
strGroup = "='" & Me.cboGroup.Value & "' "
End If
' Build the SQL string
strSQL = "SELECT SharePrices.DateTime, SharePrices.StockSymbol,
SharePrices.StockPrice, tblStocksGroup.Company, tblStocksGroup.Group,
tblStocksGroup.Class " & vbCrLf & _
"FROM SharePrices INNER JOIN tblStocksGroup ON SharePrices.StockSymbol =
tblStocksGroup.Ticker " & vbCrLf & _
"WHERE (((tblStocksGroup.Group)=[Forms]![frmMaster]![cboGroup]) AND
((tblStocksGroup.Class)=[Forms]![frmMaster]![cboClass])) " & vbCrLf & _
"Order by SharePrices.DateTime;"
' Open the Query
qdf.SQL = strSQL
DoCmd.OpenQuery "qrySummary"
Set qdf = Nothing
Set db = Nothing
End Sub
This takes strings from two ComboBoxes (cboClass and cboGroup) and passes
the string to a Query. this part works fine. I'm trying to add a capability
to choose from 20 CheckBoxes, and add these to the Query. Is that hard to
do? I'm sure it's possbile in Access, but I don't know how to do it. I've
done it in Excel, but not Access. Any thoughts or suggestions?
The names of the controls are pretty intuitive: chkJetBlue, chkContinental,
etc.
Thanks,
Ryan--
--
Ryan---
If this information was helpful, please indicate this by clicking ''Yes''.
KARL DEWEY said:
dynamically insert results from 20 yes/no checkboxes into a Query.
I do not follow you question. Do you want to put different checkbox results
in the query on the fly so that one time the results displays 1 through 5 and
next time all or some comination?
--
Build a little, test a little.
:
I am trying to figure out how to dynamically insert results from 20 yes/no
checkboxes into a Query. I'm pretty sure it will require VBA and some kind
of loop will be required, right;
For Each. . .Next
Should I add some kind of unbound object frame? Is there a good demo of how
to do this online somewhere? I googled around for an example this AM, but
didn't come up with anything useful.
Thanks!
Ryan--