Reputation: 43
I have a form that I want to open focusing to a cell and also full screen. I am using the following code:
Private Sub Form_Load()
DoCmd.Maximize
Me!Cell5.SetFocus
End Sub
It keeps giving me an error
object doesn't support this property or method
What am I doing wrong? Could you please help me to fix this code?
Upvotes: 1
Views: 938
Reputation: 350272
You cannot set the focus on an element of a form during the Load
event. Instead you should do that in the Open
or Activate
event:
Private Sub Form_Open()
Me!Cell5.SetFocus
End Sub
or:
Private Sub Form_Activate()
Me!Cell5.SetFocus
End Sub
However, instead of setting the focus on a particular element in code, go to the properties of that Cell5
and set the TabIndex
property to 0
. This will ensure that this element gets focus whenever the form is loaded.
Upvotes: 2