Hi Everyone
I have a form with a button on it. Pressing this button opens a report which displays the results from a table. I have about 7 text fields which I can use search (Name, propertyNameNumber, Street, Locality, Town, County and Postcode). So there are obviously quite a few different combinations to search by. So when searching by Name, I need the coding.....
Me.txtOffendersFullName.Value = Me.txtOffendersFullName.Value & "*"
DoCmd.OpenReport "Show Details", acViewPreview
....and when searching by name and propertyNameNumber i need the code....
Me.txtOffendersFullName.Value = Me.txtOffendersFullName.Value & "*"
Me.txtPropNameNum.Value = Me.txtPropNameNum.Value & "*"
DoCmd.OpenReport "Show Details", acViewPreview
The problem is the amount of combinations I can search by using the 7 textfields. For example the following code shows how many combinations there are and the mass amount of coding involved with only 3 combinations.
Does anyone know any other way to do this?
Thanks a lot, ohh, and here's the code........sorry about the size
If IsNull(Me.txtOffendersFullName) And IsNull(Me.txtOffendersPropertyNameNumber) _
And IsNull(Me.txtStreet) And IsNull(Me.txtLocality) _
And IsNull(Me.txtTown) And IsNull(Me.txtCounty) And IsNull(Me.txtPostcode) Then
MsgBox ("Please type in a value to search for")
Else
If IsNull(Me.txtPerName) And IsNull(Me.txtPerAddress) And Not IsNull(Me.dDownIntCat) Then
Me.dDownIntCat.Value = "*" & Me.dDownIntCat.Value & "*"
MsgBox ("Search by Int")
DoCmd.OpenForm "test1b"
DoCmd.Close acForm, "test1a"
Else
If IsNull(Me.txtPerName) And IsNull(Me.dDownIntCat) And Not IsNull(Me.txtPerAddress) Then
Me.txtPerAddress.Value = "*" & Me.txtPerAddress.Value & "*"
MsgBox ("Search by Address")
DoCmd.OpenForm "test1b"
DoCmd.Close acForm, "test1a"
Else
If IsNull(Me.txtPerAddress) And IsNull(Me.dDownIntCat) And Not IsNull(Me.txtPerName) Then
Me.txtPerName.Value = "*" & Me.txtPerName.Value & "*"
MsgBox ("Search by Name")
DoCmd.OpenForm "test1b"
DoCmd.Close acForm, "test1a"
Else
If IsNull(Me.dDownIntCat) And Not IsNull(Me.txtPerName) And Not IsNull(Me.txtPerAddress) Then
Me.txtPerName.Value = "*" & Me.txtPerName.Value & "*"
Me.txtPerAddress.Value = "*" & Me.txtPerAddress.Value & "*"
MsgBox ("Search by Name and Address")
DoCmd.OpenForm "test1b"
DoCmd.Close acForm, "test1a"
Else
If IsNull(Me.txtPerAddress) And Not IsNull(Me.txtPerName) And Not IsNull(Me.dDownIntCat) Then
Me.txtPerName.Value = "*" & Me.txtPerName.Value & "*"
Me.dDownIntCat.Value = "*" & Me.dDownIntCat.Value & "*"
MsgBox ("Search by Name and Int")
DoCmd.OpenForm "test1b"
DoCmd.Close acForm, "test1a"
Else
If IsNull(Me.txtPerName) And Not IsNull(Me.txtPerAddress) And Not IsNull(Me.dDownIntCat) Then
Me.txtPerAddress.Value = "*" & Me.txtPerAddress.Value & "*"
Me.dDownIntCat.Value = "*" & Me.dDownIntCat.Value & "*"
MsgBox ("Search by Address and Int")
DoCmd.OpenForm "test1b"
DoCmd.Close acForm, "test1a"
Else
If Not IsNull(Me.txtPerName) And Not IsNull(Me.txtPerAddress) And Not IsNull(Me.dDownIntCat) Then
Me.txtPerName.Value = "*" & Me.txtPerName.Value & "*"
Me.txtPerAddress.Value = "*" & Me.txtPerAddress.Value & "*"
Me.dDownIntCat.Value = "*" & Me.dDownIntCat.Value & "*"
MsgBox ("Search using all three fields")
DoCmd.OpenForm "test1b"
DoCmd.Close acForm, "test1a"
End If
End If
End If
End If
End If
End If
End If
DoCmd.OpenReport "Show Details", acViewPreview
End If