Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

setfocus runtime errors

Status
Not open for further replies.

sanders720

Programmer
Aug 2, 2001
421
US
Runtime error 2110 - Microsoft Access can't move the focus to the control txtTotal.

Runtime error 2185 - You can't reference a property or method for a control unless the control has the focus.


What generally causes these errors, which are coming from the lines below.

Private Sub Mach_Hours_LostFocus()
' txtTotal.SetFocus
' txtTotal.Text = Val(
Hours said:
.Text) + Val([Engineer Hours].Text) + Val([Assy Hours].Text) + Val([Mach Hours].Text * QTY)
End Sub



Thanks in advance for the help...
 
Hi!

I'm not certain why Access can't set the focus as your code requests, but it probably is because of being in the lost focus procedure. The text property of a text box holds the information while it is still being edited in a text box and therefore can only be accessed when the text box has the focus. What you want to do is use the .Value instead of .Text and then you will not need to set the focus to the text box first.

hth
Jeff Bridgham
bridgham@purdue.edu
 
It's not just a LostFocus issue, I tried it on AfterUpdate and got the same results...
 
Hi!

Well, as I said, I'm not sure why you get the error on the setfocus statement maybe because Access has already decided to set focus to another control, but, using the .Value, the setfocus issue becomes moot since you can access that property without the text box having the focus.

hth
Jeff Bridgham
bridgham@purdue.edu
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top