Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run time error 2185

Tags:

vba

ms-access

I getting a run time error 2185, "You can't reference a property or method for a control unless the control has the focus ...".

This is my code that I am using.

Private Sub Command5_Click()
    Dim cardno As Integer
    cardno = cardnumber.Text
    DoCmd.OpenForm "search_card_number", acNormal, , WHERE & cardno = [Account Number]
End Sub
like image 962
Steve Avatar asked Dec 20 '13 12:12

Steve


2 Answers

Referencing the .Text property of a control requires it to have focus. Simply drop that and it should work (the default is .Value)

OR

Try putting in the SetFocus method as advised by Access, i.e.

  Private Sub Command5_Click()
    Dim cardno As Integer

     cardnumber.SetFocus   <-------Use this line to set the focus        

    cardno = cardnumber.Text
  DoCmd.OpenForm "search_card_number", acNormal, , WHERE & cardno = [Account Number]
 End Sub
like image 51
analyticalpicasso Avatar answered Sep 22 '22 06:09

analyticalpicasso


That run time error means You can't reference a property or method for a control unless the control has the focus.

You can use .Text when a control has the focus.

like image 32
Siddharth Rout Avatar answered Sep 24 '22 06:09

Siddharth Rout