Using three text boxes

  • Thread starter Thread starter t.slaght
  • Start date Start date
T

t.slaght

I have created a form containing three text boxes that i want the user
to enter information into. The user will then press a button and it
will perform a search and all records matching the search will be
viewed in another form that is opened up with the search button. My
problem is I do not know how to make the search dependent on all three
boxes and not just one.
 
Are you comparing the values entered against a single field or three
different fields? Can you share some control, form, and field names? What do
you want to happen if 1 or more text boxes are left blank/Null?
 
Are you comparing the values entered against a single field or three
different fields? Can you share some control, form, and field names? What do
you want to happen if 1 or more text boxes are left blank/Null?

--
Duane Hookom
Microsoft Access MVP





- Show quoted text -

The values will be compared to three different fields, if one of the
fields is left blank then only search using the other 2. Blank
fields "shouldn't" be a problem in that it shouldn't occur but I
suppose I should build the code if there is that possibility.
 
Sorry didn't post this but the field Names are Reg Plan, Plan Block.
Plan Lot, the control source for all of these are by the same name and
once data is entered into these fields it will open a form called
"Main"
 
I would change the user input text box names to a naming convention like
"txtRegPlan" and then write code like:

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
'assuming Plan Block is text
strWhere = strWhere & " AND [Plan Block] =""" & Me.txtPlanBlock & """ "
End If
'-- you add the last text box code here ;-)
'-- if the fields are numeric then remove some quotes
DoCmd.OpenForm "Main", , , strWhere
 
I would change the user input text box names to a naming convention like
"txtRegPlan" and then write code like:

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
'assuming Plan Block is text
strWhere = strWhere & " AND [Plan Block] =""" & Me.txtPlanBlock & """ "
End If
'-- you add the last text box code here ;-)
'-- if the fields are numeric then remove some quotes
DoCmd.OpenForm "Main", , , strWhere

--
Duane Hookom
Microsoft Access MVP



Sorry didn't post this but the field Names are Reg Plan, Plan Block.
Plan Lot, the control source for all of these are by the same name and
once data is entered into these fields it will open a form called
"Main"- Hide quoted text -

- Show quoted text -

It works, thank you very very much
 
Back
Top