Re: Searching Through ComboBoxes

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



On Jul 2, 10:41 am, Kgwil...@xxxxxxxxx wrote:
On Jul 2, 10:17 am, Kgwil...@xxxxxxxxx wrote:





I have been trying for the last week to create a form that allows
users to search two fields in order to find it in a database with all
of it's additional information.

I have been using macros up until this point. It has become too
complicated for the use of macros for what I am trying to do, so I'm
going to need some kind of code for the task that I need the form to
do.

Here's the details.
The form that I'm working on is named SearchProjectInventory. It has
2 combo boxes and 1 command button. The first combobox is for the ID
of a project. The name of the combobox is PARID. The second combobox
is named BO_Project_Name. The command button is named Search. The
combo boxes are linked to a table which is named Project_Inventory. I
also need the information filtered inside of the combo boxes. They
currently show duplicate entries for some reason.

Okay, what I need the form to do is simply be able to search both of
the combo boxes separately if need be. Say for instance the user
knows the BO_Project_Name but doesn't know the PARID, then the form
still needs to be able to function. The same goes in vice versa. The
form needs to be able to search if one combo box is filled or both.

I already have another form that will be populated by this one. It is
named Project_Inventory. So when I click the Search button on the
SearchProjectInventory form it should bring up the Project_Inventory
form populated with the information you are looking for.

Thanks in advance

Some one on the forms section helped me earlier, but I'm getting a
type mismatch error when I click Search. Here's the code that he made
for it...

Private Sub Search_Click()
On Error GoTo Err_Search_Click

Dim stDocName As String
Dim stLinkCriteria As String

'change this to the name of your results form
stDocName = "Project_Inventory"

'check for selection in first combo box
'change COMBO1 to the name of your combo box
If Not IsNull(Me.PARID) Then
stLinkCriteria = "[PARID] = " & Me.PARID & " AND "
End If

'check for selection in second combo box
'change COMBO2 to the name of your combo box
If Not IsNull(Me.BO_Project_Name) Then
stLinkCriteria = "[BO_Project_Name] = " & Me.BO_Project_Name &
" AND "
End If

'remove the last 5 chars
If Len(stLinkCriteria) > 0 Then
stLinkCriteria = Left(stLinkCriteria, Len(stLinkCriteria)) - 5
End If

'open form filtered by criteria
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_Search_Click:
Exit Sub

Err_Search_Click:
MsgBox Err.Description
Resume Exit_Search_Click

End Sub- Hide quoted text -

- Show quoted text -

If PARID is text, then include single quotes in the SQL string:
stLinkCriteria = "[PARID] =' " & Me.PARID & " ' AND "

.


Quantcast