SelStart Error - Run-time 2185

S

ScottS

I have been using input masks for dates on forms. I usually add code to
force the cursor to the beginning of the text box using SelStart.

Private Sub txtDate1_GotFocus()
Me.txtDate1.SelStart = 0
End Sub

I created a form and the above field functioned fine. After I added more
controls and code I began to get a Run-time 2185 error -You can't reference a
property or method for a control unless the control has the focus.

Anyone know what causes this or is my form corrupted in some way?

Thanks in advance for any help or insight,
 
A

Allen Browne

Scott, the only case that comes to mind is where:
- You have a form that contains no records, and
- No new records can be added.

In this case, the detail section goes completely blank. Any controls in the
Form Header or Form Footer sections still show, but Access gets confused and
can show this error message. More info in the first section of this article:
http://allenbrowne.com/bug-06.html
 
L

Linq Adams via AccessMonster.com

"You can't reference a property or method for a control unless the control
has the focus."

So Access is saying that you're trying to do something to ControlA that you
can only do when ControlA has focus, and ControlA doesn't have focus!

One possibilty that comes to mind, especially when you speak of adding
multiple controls and using the identical code on all of them, is that you've
copied and pasted code and forgotten to change the control name in the code.

Say you start with

Private Sub txtDate1_GotFocus()
Me.txtDate1.SelStart = 0
End Sub

then you add a new field, txtDate2. You copy and paste the above sub, and
change txtDate1 to txtDate2 in the sub title, but forget to do so in the body
of the sub, so that you end up with this

Private Sub txtDate2_GotFocus()
Me.txtDate1.SelStart = 0
End Sub

Now, when txtDate2 gets the focus, you're trying to set SelStart for txtDate1,
and you'll get your 2185 error message. .
 
S

ScottS

Thanks Allen. You absoultely nailed this one and without your help there is
no way I would have found it.

The fields in question were in my form header. The detail section was not
displaying records as you pointed out. When I removed the record sources,
the SelStart worked as it should.

I will have to figure out a way to work around this problem.

Thanks again!
 
S

ScottS

Thanks for your help with this. I checked my code and it was correct, but
problem you pointed out to me did happen to me in the past so it was well
worth checking it out.

Thanks for your help.
 

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

Top