Search Form Problem

  • Thread starter Thread starter MartinR
  • Start date Start date
M

MartinR

Hello!
I created a form in design view using Allen Browne's example as my
basis. I have copied the properties and code from this and yet my
programme refuses to work for me. Allen Browne's programme is avaiable
at http://allenbrowne.com/ser-62.html.

When I open the form in the place where the results of the search
should appear is this - #Name?

Could anybody help me out here!! I'd appriciate any help!
 
#Name indicates that at least one of the controls in the form is bound to an
expression that Access cannot resolve.

It could be because the Control Source of a text box refers to a field that
is not in the RecordSource of the form, or because there is a naming clash
with something else, because Access is confused about the name, or because
the control has the same name as a field, but is bound to something else.
 
Ok so how should I resolve this problem, I have tries recreating the
form trough wizard so that I would have options for the control source,
however in that form neither the search or clear buttons work. I have a
feeling that it is a filter setting problem, I could be way off though!

Would you have any idea what address I should enter in the control
source property?? I have tried numerous but none of them seem to work!

Thanks again!
 
Ok so how should I resolve this problem, I have tried recreating the
form trough wizard so that I would have options for the control source,
however in that form neither the search or clear buttons work. I have a
feeling that it is a filter setting problem, I could be way off though!

Would you have any idea what address I should enter in the control
source property?? I have tried numerous but none of them seem to work!

Thanks again!
 
What is the Record Source for your table?
- Is it a table?
- A query?
- A SQL statement?

What is the Control Source of the field that shows #Name?
- Is it a field name?
- An expression starting with "="?
- Blank?

Whatever the Control Source is, it needs to match the fields in the Record
Source.
 
Allen said:
What is the Record Source for your table?
- Is it a table?
- A query?
- A SQL statement?

What is the Control Source of the field that shows #Name?
- Is it a field name?
- An expression starting with "="?
- Blank?

Whatever the Control Source is, it needs to match the fields in the Record
Source


the record source is a table, the control source may as well be blank
but I have written in what should appear on the drop down list.

I have them matching in the second form I created and all the exact
same code design and properties but that just doesn't work!!

Thanks for the help!!
 
Not sure I follow, but if you think the Control Source might as well be
blank perhaps you could leave it blank and solve the problem that way.
 
Hey sorry for being unclear. I was wondering if you could possiably
take a look at my programme for a minute and just briefly see if you
can spot the problem because I cannot work it out at all, and if I
don't find out what the problem is I probably go insane!!

If you don't want to its ok, I just thought It was worth asking.

Thanks a million!
 
Hi Martin

Thanks for asking, but we really can't open everyone's databases up and sort
out all the issues. We would never get anything done at all that way.
 
Thats grand, just thought I'd chance my arm! I've basicaly got it
sorted apart fom the a few problems.

When I press the search button no records appear but if I cress the
slear button after then 1 record comes up, and its the same record
every time.

Then when I press the clear button after that it clears the criteria
fields but doesnt clear the results. the results only clears when I
press the search button again!

Thanks again!
 
Hi again. I've used the "Stop" plus F8 method to go through my code to
see what my search button is actually doing. It does everythinbg right
but no results are being displayed in the detail part of the form. I
must be missing something small what might it be.
Here is a copy of the code i have behind my search button:

Private Sub Search_Click()

'Purpose: Build up the criteria string form the non-blank search
boxes, and apply to the form's Filter.
'Notes: 1. We tack " AND " on the end of each condition so you
can easily add more search boxes; _
we remove the trailing " AND " at the end.
' 2. The date range works like this: _
Both dates = only dates between (both
inclusive. _
Start date only = all dates from this one
onwards; _
End date only = all dates up to (and
including this one).
Dim strWhere As String 'The criteria string.
Dim lngLen As Long 'Length of the criteria
string to append to.
Const conJetDate = "\#mm\/dd\/yyyy\#" 'The format expected for
dates in a JET query string.


'***********************************************************************
'Look at each search box, and build up the criteria string from the
non-blank ones.

'***********************************************************************

'Number field example. Do not add the extra quotes.
If Not IsNull(Me.cbofilterCableType) Then
strWhere = strWhere & "([Cable Type] Like "" * " &
Me.cbofilterCableType & " * "") AND "
End If

If Not IsNull(Me.cbofilterSiteDrumNo) Then
strWhere = strWhere & "([Site Drum No] Like "" * " &
Me.cbofilterSiteDrumNo & " * "") AND "
End If

If Not IsNull(Me.cbofilterManufacturer) Then
strWhere = strWhere & "([Manufacturer] Like "" * " &
Me.cbofilterManufacturer & " * "") AND "
End If

If Not IsNull(Me.cbofilterSize) Then
strWhere = strWhere & "([Size] Like "" * " & Me.cbofilterSize &
" * "") AND "
End If

If Not IsNull(Me.cbofilterCores) Then
strWhere = strWhere & "([Cores] Like "" * " & Me.cbofilterCores
& " * "") AND "
End If

If Not IsNull(Me.cbofilterConductor) Then
strWhere = strWhere & "([Conductor] Like "" * " &
Me.cbofilterConductor & " * "") AND "
End If

If Not IsNull(Me.cbofilterConductorType) Then
strWhere = strWhere & "([Conductor Type] Like "" * " &
Me.cbofilterConductorType & " * "") AND "
End If

If Not IsNull(Me.cbofilterStandard) Then
strWhere = strWhere & "([Standard] Like "" * " &
Me.cbofilterStandard & " * "") AND "
End If

If Not IsNull(Me.cbofilterVoltageRange) Then
strWhere = strWhere & "([Voltage Range] Like "" * " &
Me.cbofilterVoltageRange & " * "") AND "
End If

If Not IsNull(Me.cbofilterOutsideDiammeter) Then
strWhere = strWhere & "([Outside Diammeter] Like "" * " &
Me.cbofilterOutsideDiammeter & "*"") AND "
End If

' If Not IsNull(Me.cbofilterArmoured) Then
' strWhere = strWhere & "([Armoured] Like "" * " &
Me.cbofilterArmoured & " * "") AND "
' End If

If Not IsNull(Me.cbofilterLocation) Then
strWhere = strWhere & "([Location] Like "" * " &
Me.cbofilterLocation & " * "") AND "
End If
'Yes/No field and combo example. If combo is blank or contains
"ALL", we do nothing.
If Me.cbofilterArmoured = -1 Then
strWhere = strWhere & "([Armoured] = True) AND "
ElseIf Me.cbofilterArmoured = 0 Then
strWhere = strWhere & "([Armoured] = False) AND "
End If



'***********************************************************************
'Chop off the trailing " AND ", and use the string as the form's
Filter.

'***********************************************************************
'See if the string has more than 5 characters (a trailng " AND ")
to remove.
lngLen = Len(strWhere) - 5
If lngLen <= 0 Then 'Nah: there was nothing in the string.
MsgBox "No criteria", vbInformation, "Nothing to do."
Else 'Yep: there is something there, so remove
the " AND " at the end.
strWhere = Left$(strWhere, lngLen)
'For debugging, remove the leading quote on the next line.
Prints to Immediate Window (Ctrl+G).
'Debug.Print strWhere

'Finally, apply the string as the form's Filter.
Me.Filter = strWhere
Me.FilterOn = True
End If

End Sub


Any helpful tips would be great,
thanks
Martin
 
Time to "divide and conquor."

Get it working with just one or two criteria.
Once you have that working, you can add a couple more, and so on.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

MartinR said:
Hi again. I've used the "Stop" plus F8 method to go through my code to
see what my search button is actually doing. It does everythinbg right
but no results are being displayed in the detail part of the form. I
must be missing something small what might it be.
Here is a copy of the code i have behind my search button:

Private Sub Search_Click()

'Purpose: Build up the criteria string form the non-blank search
boxes, and apply to the form's Filter.
'Notes: 1. We tack " AND " on the end of each condition so you
can easily add more search boxes; _
we remove the trailing " AND " at the end.
' 2. The date range works like this: _
Both dates = only dates between (both
inclusive. _
Start date only = all dates from this one
onwards; _
End date only = all dates up to (and
including this one).
Dim strWhere As String 'The criteria string.
Dim lngLen As Long 'Length of the criteria
string to append to.
Const conJetDate = "\#mm\/dd\/yyyy\#" 'The format expected for
dates in a JET query string.


'***********************************************************************
'Look at each search box, and build up the criteria string from the
non-blank ones.

'***********************************************************************

'Number field example. Do not add the extra quotes.
If Not IsNull(Me.cbofilterCableType) Then
strWhere = strWhere & "([Cable Type] Like "" * " &
Me.cbofilterCableType & " * "") AND "
End If

If Not IsNull(Me.cbofilterSiteDrumNo) Then
strWhere = strWhere & "([Site Drum No] Like "" * " &
Me.cbofilterSiteDrumNo & " * "") AND "
End If

If Not IsNull(Me.cbofilterManufacturer) Then
strWhere = strWhere & "([Manufacturer] Like "" * " &
Me.cbofilterManufacturer & " * "") AND "
End If

If Not IsNull(Me.cbofilterSize) Then
strWhere = strWhere & "([Size] Like "" * " & Me.cbofilterSize &
" * "") AND "
End If

If Not IsNull(Me.cbofilterCores) Then
strWhere = strWhere & "([Cores] Like "" * " & Me.cbofilterCores
& " * "") AND "
End If

If Not IsNull(Me.cbofilterConductor) Then
strWhere = strWhere & "([Conductor] Like "" * " &
Me.cbofilterConductor & " * "") AND "
End If

If Not IsNull(Me.cbofilterConductorType) Then
strWhere = strWhere & "([Conductor Type] Like "" * " &
Me.cbofilterConductorType & " * "") AND "
End If

If Not IsNull(Me.cbofilterStandard) Then
strWhere = strWhere & "([Standard] Like "" * " &
Me.cbofilterStandard & " * "") AND "
End If

If Not IsNull(Me.cbofilterVoltageRange) Then
strWhere = strWhere & "([Voltage Range] Like "" * " &
Me.cbofilterVoltageRange & " * "") AND "
End If

If Not IsNull(Me.cbofilterOutsideDiammeter) Then
strWhere = strWhere & "([Outside Diammeter] Like "" * " &
Me.cbofilterOutsideDiammeter & "*"") AND "
End If

' If Not IsNull(Me.cbofilterArmoured) Then
' strWhere = strWhere & "([Armoured] Like "" * " &
Me.cbofilterArmoured & " * "") AND "
' End If

If Not IsNull(Me.cbofilterLocation) Then
strWhere = strWhere & "([Location] Like "" * " &
Me.cbofilterLocation & " * "") AND "
End If
'Yes/No field and combo example. If combo is blank or contains
"ALL", we do nothing.
If Me.cbofilterArmoured = -1 Then
strWhere = strWhere & "([Armoured] = True) AND "
ElseIf Me.cbofilterArmoured = 0 Then
strWhere = strWhere & "([Armoured] = False) AND "
End If



'***********************************************************************
'Chop off the trailing " AND ", and use the string as the form's
Filter.

'***********************************************************************
'See if the string has more than 5 characters (a trailng " AND ")
to remove.
lngLen = Len(strWhere) - 5
If lngLen <= 0 Then 'Nah: there was nothing in the string.
MsgBox "No criteria", vbInformation, "Nothing to do."
Else 'Yep: there is something there, so remove
the " AND " at the end.
strWhere = Left$(strWhere, lngLen)
'For debugging, remove the leading quote on the next line.
Prints to Immediate Window (Ctrl+G).
'Debug.Print strWhere

'Finally, apply the string as the form's Filter.
Me.Filter = strWhere
Me.FilterOn = True
End If

End Sub


Any helpful tips would be great,
thanks
Martin
 
Hi allen,

What i have done now is disabled all bar two of my search boxes, but
again when i press the search button. nothing happens. When i look at
my code using stop and F8 i can see that the right criteria is asigned
to the right variables. So i am pretty sure the code is working. what
appears to be happening is the filter is correct but the filter is not
connected to where my results are to be displayed. What property should
i alter in the text boxes to activate the filter?

Martin
 
When you step through, do you see it setting the Filter property of the
form?

Then does it set the FilterOn property successfully?
 
It sets "Me.FilterOn = True" in the code behing the search button.
However in the
"Private Sub Form_Open(Cancel As Integer)" section it has "Me.FilterOn
= True" commeted out. Will that make a difference?

Martin
 
Which form are you wanting to set the Filter on: the original form, or the
one that you just opened?

Yes, it does make a difference which form you apply the filter string to and
set the FilterOn for.
 
I amn't opening any form to show the results. The way i have it set up
is:

In the header of the form i have my criteria boxes and also have the
button called search. When i click this button i want the results of
the filter to show up in the details part of the same form. I have text
boxes set up to display the results.

Is this the best way to display the results or is there an easier way
to show them? If so, what way can i do this..

Regards,
Martin
 
Okay, I'm not sure what the Form_Open code was about then.

I think I've gone as far as I can with this thread.
You already have the sample database to work from, so hopefully you will be
able to debug yours and verify that the Filter is being set correctly, and
the FilterOn is set also.
 

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

Back
Top