An error regarding the Search Box

emsadoon

Registered User.
Local time
Today, 18:42
Joined
Jun 6, 2013
Messages
83
Hi,
I have used one of the members' code which was posted in a tread before to create a search box in a form. This code works perfectly when the form itself is open. Otherwise, when I put this searching form along with other forms in one navigation form, I get the following error:
"Enter Parameter Value:
Forms!FRM_SearchMulti!SrchText"

The code that was used for the Search box is as following:

Private Sub SearchFor_Change()

'Create a string (text) variable
Dim vSearchString As String

'Populate the string variable with the text entered in the Text Box SearchFor
vSearchString = SearchFor.Text

'Pass the value contained in the string variable to the hidden text box SrchText,
'that is used as the sear4ch criteria for the Query QRY_SearchAll
SrchText.Value = vSearchString

'Requery the List Box to show the latest results for the text entered in Text Box SearchFor
Me.SearchResults.Requery


'Tests for a trailing space and exits the sub routine at this point
'so as to preserve the trailing space, which would be lost if focus was shifted from Text Box SearchFor
If Len(Me.SrchText) <> 0 And InStr(Len(SrchText), SrchText, " ", vbTextCompare) Then
Exit Sub
End If

'Set the focus on the first item in the list box
Me.SearchResults = Me.SearchResults.ItemData(1)
Me.SearchResults.SetFocus

'Requery the form to refresh the content of any unbound text box that might be feeding off the record source of the List Box
DoCmd.Requery

'Returns the cursor to the the end of the text in Text Box SearchFor
Me.SearchFor.SetFocus

If Not IsNull(Len(Me.SearchFor)) Then
Me.SearchFor.SelStart = Len(Me.SearchFor)
End If


End Sub


I appreciate it if you can help me with this matter.
 
You would have created a Query along with the Form Creation.. The Query criteria would have the reference to the Form you created.. Change it to match your new design..
 
Thanks Paul for your help. I actually changed the reference to the correct form. But, the form that I have is a navigation form with several buttons,which open other forms. When I changed the refernce, I do not get any error, but my search box does not work.
 
Okay make this clear.. Is it a Navigation Form using the Navigation Form Option in Form wizard? Or just a Form with button that acts like a Navigation Form? If it is a Navigation form then you need to refer the Form differently.. as they are SubForm to the Main (Navigation) Form..
 
It is a Navigation Form using the Naviagtion Form wizard with one level subforms.
 
Thanks, I used the link you put above and it worked.
 
I also get an error when using the search box

When someone enters text to search and they use capital I

I get
run time error 2110
Microsoft Access can't move the focus to the control SearchResults

The code in question is


'Set the focus on the first item in the list box
Me.SearchResults = Me.SearchResults.ItemData(1)
Me.SearchResults.SetFocus


Its the last line of the above code that is highlighted when I take the debug path.

The results box on the form is named SearchResults

Any help would be appreciated
 

Users who are viewing this thread

Back
Top Bottom