B
Ben via AccessMonster.com
I have a search for with two text boxes. I have a button named “searchâ€, so
that on click of the search button, the code should search for values in the
text boxes and then show the results in the sub form. I can only get the
first text box to work. I enter a value in the first text box, click the
search button and it returns the correct values in the subform. But, when I
enter a value in the second text box I get the msg “you can’t reference a
property or method for a control unless the control has the focusâ€.
Here is my code below:
Can any tell me what I am doing wrong?
Thanks,
Ben
Private Sub PwrSearch_Click()
On Error GoTo Err_PwrSearch_Click
'
' For Data Entry Search Form
Dim strSQL As String
'Search for any value in SearchText
If Not IsNull(Me.SearchText.Text) Then GoTo AN_PwrSearch_Click:
AN_PwrSearch_Click:
Me.SearchText.SetFocus
Me.SearchText2.Value = Null
Me.SearchText2.SetFocus
strSQL = "select * from tblDE2 where Name Like '*" & Me.SearchText.Value
& "*'"
MsgBox "set string"
Me.sfrmSearch.Form.RecordSource = strSQL
Me.sfrmSearch.Requery
‘Move null to all the text boxes for another search
Me.SearchText.Value = Null
Me.SearchText2.Value = Null
GoTo Exit_PwrSearch_Click
Exit Sub
'Search for next text box
If Not IsNull(Me.SearchText2.Text) Then GoTo IMMO_PwrSearch_Click:
IMMO_PwrSearch_Click:
Me.SearchText2.SetFocus
Me.SearchText.Value = Null
Me.SearchText3.SetFocus
strSQL = "select * from tblDE2 where Name2 Like '*" & Me.SearchText2.
Value & "*'"
MsgBox "set string"
Me.sfrmSearch.Form.RecordSource = strSQL
Me.sfrmSearch.Requery
‘Move null to all the text boxes for another search
Me.SearchText.Value = Null
Me.SearchText2.Value = Null
Exit Sub
Exit_PwrSearch_Click:
Exit Sub
Err_PwrSearch_Click:
MsgBox Err.Description
Resume Exit_PwrSearch_Click
End Sub
that on click of the search button, the code should search for values in the
text boxes and then show the results in the sub form. I can only get the
first text box to work. I enter a value in the first text box, click the
search button and it returns the correct values in the subform. But, when I
enter a value in the second text box I get the msg “you can’t reference a
property or method for a control unless the control has the focusâ€.
Here is my code below:
Can any tell me what I am doing wrong?
Thanks,
Ben
Private Sub PwrSearch_Click()
On Error GoTo Err_PwrSearch_Click
'
' For Data Entry Search Form
Dim strSQL As String
'Search for any value in SearchText
If Not IsNull(Me.SearchText.Text) Then GoTo AN_PwrSearch_Click:
AN_PwrSearch_Click:
Me.SearchText.SetFocus
Me.SearchText2.Value = Null
Me.SearchText2.SetFocus
strSQL = "select * from tblDE2 where Name Like '*" & Me.SearchText.Value
& "*'"
MsgBox "set string"
Me.sfrmSearch.Form.RecordSource = strSQL
Me.sfrmSearch.Requery
‘Move null to all the text boxes for another search
Me.SearchText.Value = Null
Me.SearchText2.Value = Null
GoTo Exit_PwrSearch_Click
Exit Sub
'Search for next text box
If Not IsNull(Me.SearchText2.Text) Then GoTo IMMO_PwrSearch_Click:
IMMO_PwrSearch_Click:
Me.SearchText2.SetFocus
Me.SearchText.Value = Null
Me.SearchText3.SetFocus
strSQL = "select * from tblDE2 where Name2 Like '*" & Me.SearchText2.
Value & "*'"
MsgBox "set string"
Me.sfrmSearch.Form.RecordSource = strSQL
Me.sfrmSearch.Requery
‘Move null to all the text boxes for another search
Me.SearchText.Value = Null
Me.SearchText2.Value = Null
Exit Sub
Exit_PwrSearch_Click:
Exit Sub
Err_PwrSearch_Click:
MsgBox Err.Description
Resume Exit_PwrSearch_Click
End Sub