using form with combobox to initiate query

P

papa jonah

I have a query that runs great. However, the criteria are frequently
changed. I would like to facilitate this by using a combobox to select
the "type" (one of the criteria), hit a command button, and let it rip.

The onclick event for the command button (generated through the wizard)
is:
Private Sub Command4_Click()
On Error GoTo Err_Command4_Click
Dim stDocName As String
stDocName = "qryDirectorate"
DoCmd.OpenQuery stDocName, acNormal, acEdit
Exit_Command4_Click:
Exit Sub
Err_Command4_Click:
MsgBox Err.Description
Resume Exit_Command4_Click

I have a combobox (cbotype) that I want to use to tell this code how to
limit the query.
I have looked at some coding examples, but they don't seem to address
this.
Any thoughts would be greatly appreciated.

Currently the SQL for the query is:
SELECT [ORPS Data].Discovery_Date, [ORPS Data].Wt, [Zlookup:
Type].Type, QryDivision.Division, [ORPS Data].[ORPS Designator],
QryDivision.AD
FROM [Zlookup: Type] INNER JOIN ([Zlookup: Subtype] INNER JOIN (([ORPS
Data] INNER JOIN QryDivision ON [ORPS Data].[ORPS Designator] =
QryDivision.[ORPS Designator]) INNER JOIN TblTypeSubType ON [ORPS
Data].[ORPS Designator] = TblTypeSubType.[ORPS Designator]) ON
[Zlookup: Subtype].SubtypeID = TblTypeSubType.idSubtype) ON [Zlookup:
Type].TypeID = TblTypeSubType.Type
WHERE ((([ORPS Data].Discovery_Date)>#10/1/1992# And ([ORPS
Data].Discovery_Date)<#10/1/2005#) AND (([ORPS Data].Wt)<>"1") AND
(([Zlookup: Type].Type) Like "elect*") AND (([ORPS
Data].Status)<>"can"))
ORDER BY [ORPS Data].Discovery_Date;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top