Adding a combo box to a search form containing text boxes

T

Tyler

I have already created a working search form using three text boxes.
i would like to add a combo box to the search form.

I currently have the code

Dim strWhere As String
strWhere = "1=1 "
If Not IsNull(Me.txtRegPlan) Then
'assuming Reg Plan is text
strWhere = strWhere & " AND [Reg Plan] =""" & Me.txtRegPlan & """ "
End If
If Not IsNull(Me.txtPlanBlock) Then

strWhere = strWhere & " AND [Plan Block] =""" & Me.txtPlanBlock &
""" "
End If
If Not IsNull(Me.txtPlanLot) Then
'assuming Plan Block is text
strWhere = strWhere & " AND [Plan Lot] =""" & Me.txtPlanLot & """ "
End If


DoCmd.Close
DoCmd.OpenForm "Main", , , strWhere

The field I would like to add is called Municipality. Does anyone have
any suggestions on how I would go about doing this?

thanks
 
A

Allen Browne

The code you currently have will need to chop the leading " AND " from the
string to get it to work.

Adding another filed is just adding another IF block. The extra quotes apply
if it is a Text field.

If you want a sample database that does something similar, see:
http://allenbrowne.com/ser-62.html
 
M

Marshall Barton

Tyler said:
I have already created a working search form using three text boxes.
i would like to add a combo box to the search form.

I currently have the code

Dim strWhere As String
strWhere = "1=1 "
If Not IsNull(Me.txtRegPlan) Then
'assuming Reg Plan is text
strWhere = strWhere & " AND [Reg Plan] =""" & Me.txtRegPlan & """ "
End If
If Not IsNull(Me.txtPlanBlock) Then

strWhere = strWhere & " AND [Plan Block] =""" & Me.txtPlanBlock &
""" "
End If
If Not IsNull(Me.txtPlanLot) Then
'assuming Plan Block is text
strWhere = strWhere & " AND [Plan Lot] =""" & Me.txtPlanLot & """ "
End If


DoCmd.Close
DoCmd.OpenForm "Main", , , strWhere

The field I would like to add is called Municipality. Does anyone have
any suggestions on how I would go about doing this?


Do it the same way, just make sure the combo box's
BoundColumn property corresponds to field you are searching.

If you do not understand what you have already done in your
form, try searching in VBA Help (use Ctrl+G from Access
window) for any specific item that is not clear to you.

If you have already tried all that, please ask a specific
question about the part that you could not get to work.
 

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