Hello!
I am currently working on enabling a combobox search on one of my forms [frm_Participant Info Quick View]. The complication on this is that I am hoping to allow users to specify which of 4 fields ("DB ID", "Study ID", "Last Name" and "First Name") they would like to search for a given value. Currently, I have this set up via two combo boxes and VBA code to define how they interact.
The first box, Me.Search_In, is a simple list of the four fields they can select ("DB ID", "Study ID", "Last Name" and "First Name"). The second box, Me.Search_For, is set to display all values for these 4 fields from [tbl_Participant Info]. The idea is that if you select "DB ID" in Search_In then Search_For will search for participant with a given DB ID. On the other hand, if you select "First Name" in Search_In, Search_For will search by First Name.
The issue I am having is that only the DB ID option works. For all the others, I get an error saying that the value in Search_For "isn't an item in the list" even though I know that it is.
My code is as follows:
I do not know if this is the best way to accomplish my goal, so please let me know if you have a better method. Thank you so much!!!!Code:Private Sub Search_For_AfterUpdate() Dim rs As DAO.Recordset If Not IsNull(Me.Search_For) Then 'Save before move. If Me.Dirty Then Me.Dirty = False End If 'Search in the clone set. Set rs = Me.RecordsetClone If Me.Search_In = "DB ID" Then rs.FindFirst "[DB ID] = " & Me.Search_For.Column(0) If rs.NoMatch Then MsgBox "Record Not Found. Please Search Again." Me.Search_For = "" Else 'Display the found record in the form. Me.Bookmark = rs.Bookmark Set rs = Nothing End If ElseIf Me.Search_In = "Study ID" Then rs.FindFirst "[Study ID] = " & Me.Search_For.Column(1) If rs.NoMatch Then MsgBox "Record Not Found. Please Search Again." Me.Search_For = "" Else 'Display the found record in the form. Me.Bookmark = rs.Bookmark Set rs = Nothing End If ElseIf Me.Search_In = "Last Name" Then rs.FindFirst "[LName] = """ & Me.Search_For.Column(2) & """" If rs.NoMatch Then MsgBox "Record Not Found. Please Search Again." Me.Search_For = "" Else 'Display the found record in the form. Me.Bookmark = rs.Bookmark Set rs = Nothing End If ElseIf Me.Search_In = "First Name" Then rs.FindFirst "[FName] = """ & Me.Search_For.Column(3) & """" If rs.NoMatch Then MsgBox "Record Not Found. Please Search Again." Me.Search_For = "" Else 'Display the found record in the form. Me.Bookmark = rs.Bookmark Set rs = Nothing End If End If End If End Sub Private Sub Search_In_AfterUpdate() If Me.Search_In = "DB ID" Then Me.Search_For.BoundColumn = 1 ElseIf Me.Search_In = "Study ID" Then Me.Search_For.BoundColumn = 2 ElseIf Me.Search_In = "Last Name" Then Me.Search_For.BoundColumn = 3 ElseIf Me.Search_In = "First Name" Then Me.Search_For.BoundColumn = 4 End If End Sub