Hi,
I've been working on trying to use a combo box to filter my records for
a while now, and can't get it to work. Right now, I have SQL code
written into IfThen statements on the afterupdate for the combobox. I
tried using the docmd.runSQL but from looking at previous posts, it
seems that I need to use DoCmd.OpenQuery instead since I do not have an
action SQL statement.
The short term problem is that when the user selects from the combobox,
Im getting a "type mis-match error." The longer term problem is that
once the records are filtered, I need to use the procedure number of
the filtered record to filter another set of documents(will worry about
this problem later). It might just something simple with my code, but
I'm not sure. Any help would be VERY much appreciated.
Some details/questions:
-combobox (combo1): unbound
-Does the filtered records need to be in a subform, or can it be in the
same form as the combobox?
-the combo box has two fields, only showing the second one that has the
text in it. The first hidden column is a [TypeID] that I was trying to
use in the code.
code:
************************
Private Sub combo1_AfterUpdate()
Dim ComboSortSQL As String
Dim dbs As Database
Dim qdf As QueryDefs
Set dbs = CurrentDb()
If combo1.Value = "1" Then 'Standard Procedures
ComboSortSQL = "SELECT * FROM tbl_Procedures WHERE
tbl_Procedures.[TypeID] = 1;"
Set qdf = dbs.CreateQueryDef("ComboSortSQL", ComboSortSQL)
DoCmd.OpenQuery qdf
DoCmd.DeleteObject acQuery, ComboSortSQL
ElseIf combo1.Value = 2 Then 'Policy
ComboSortSQL = "SELECT * FROM tbl_Procedures WHERE
tbl_Procedures.TypeID.Value = 2;"
Set qdf = dbs.CreateQueryDef("ComboSortSQL", ComboSortSQL)
DoCmd.OpenQuery qdf
DoCmd.DeleteObject acQuery, ComboSortSQL
ElseIf combo1.Value = 3 Then 'Process Description
ComboSortSQL = "SELECT * FROM tbl_Procedures WHERE
tbl_Procedures.TypeID.Value = 3;"
Set qdf = dbs.CreateQueryDef("ComboSortSQL", ComboSortSQL)
DoCmd.OpenQuery qdf
DoCmd.DeleteObject acQuery, ComboSortSQL
ElseIf combo1.Value = 4 Then 'Program Description
ComboSortSQL = "SELECT * FROM tbl_Procedures WHERE
tbl_Procedures.TypeID.Value = 4;"
Set qdf = dbs.CreateQueryDef("ComboSortSQL", ComboSortSQL)
DoCmd.OpenQuery qdf
DoCmd.DeleteObject acQuery, ComboSortSQL
ElseIf combo1.Value = 5 Then 'Training Program
ComboSortSQL = "SELECT * FROM tbl_Procedures WHERE
tbl_Procedures.TypeID.Value = 5;"
Set qdf = dbs.CreateQueryDef("ComboSortSQL", ComboSortSQL)
DoCmd.OpenQuery qdf
DoCmd.DeleteObject acQuery, ComboSortSQL
ElseIf combo1.Value = 6 Then 'Qualification
ComboSortSQL = "SELECT * FROM tbl_Procedures WHERE
tbl_Procedures.TypeID.Value = 6;"
Set qdf = dbs.CreateQueryDef("ComboSortSQL", ComboSortSQL)
DoCmd.OpenQuery qdf
DoCmd.DeleteObject acQuery, ComboSortSQL
ElseIf combo1.Value = 7 Then 'Standard / Specification
ComboSortSQL = "SELECT * FROM tbl_Procedures WHERE
tbl_Procedures.TypeID.Value = 7;"
Set qdf = dbs.CreateQueryDef("ComboSortSQL", ComboSortSQL)
DoCmd.OpenQuery qdf
DoCmd.DeleteObject acQuery, ComboSortSQL
ElseIf combo1.Value = 8 Then 'Guidance & Reference Documents
ComboSortSQL = "SELECT * FROM tbl_Procedures WHERE
tbl_Procedures.TypeID.Value = 8;"
Set qdf = dbs.CreateQueryDef("ComboSortSQL", ComboSortSQL)
DoCmd.OpenQuery qdf
DoCmd.DeleteObject acQuery, ComboSortSQL
End If
dbs.Close
Set qdf = Nothing
Set dbs = Nothing
End Sub
**********************