Search Text Box error can’t reference a property or method for a control

  • Thread starter Ben via AccessMonster.com
  • Start date
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
 
D

Douglas J. Steele

You're referring to the .Text property of the control. You can only use the
Text property if the control has focus. Try

If Not IsNull(Me.SearchText.Value) Then GoTo AN_PwrSearch_Click

or

If Not IsNull(Me.SearchText) Then GoTo AN_PwrSearch_Click
 
B

Ben via AccessMonster.com

Thank you!

But now it's making me physically place the cursor in the other text box in
order for the results to display. me.searchtext2.gotFocus is not moving the
cursor from the first text box to the next textbox.

Ben
You're referring to the .Text property of the control. You can only use the
Text property if the control has focus. Try

If Not IsNull(Me.SearchText.Value) Then GoTo AN_PwrSearch_Click

or

If Not IsNull(Me.SearchText) Then GoTo AN_PwrSearch_Click
I have a search for with two text boxes. I have a button named "search",
so
[quoted text clipped - 77 lines]
 
D

Douglas J. Steele

Why are you bothering to set the focus? Using the syntax I said to, it's
completely unnecessary.

(and it's SetFocus to move the focus, not gotFocus)

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Ben via AccessMonster.com said:
Thank you!

But now it's making me physically place the cursor in the other text box
in
order for the results to display. me.searchtext2.gotFocus is not moving
the
cursor from the first text box to the next textbox.

Ben
You're referring to the .Text property of the control. You can only use
the
Text property if the control has focus. Try

If Not IsNull(Me.SearchText.Value) Then GoTo AN_PwrSearch_Click

or

If Not IsNull(Me.SearchText) Then GoTo AN_PwrSearch_Click
I have a search for with two text boxes. I have a button named "search",
so
[quoted text clipped - 77 lines]
 
B

Ben via AccessMonster.com

Got it. Thanks!
Douglas said:
Why are you bothering to set the focus? Using the syntax I said to, it's
completely unnecessary.

(and it's SetFocus to move the focus, not gotFocus)
Thank you!
[quoted text clipped - 21 lines]
 

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

Similar Threads


Top