Error 2185: You can't reference a property or method for a control unless the control has focus

I have updated a tiny Event procedure to automatically fill in values of one textbox when another has been filled in, however, I am getting an error
Option Compare Database

Private Sub ConsumptionPer100KMs_AfterUpdate()
    [ConsumptionInMilesPerGallon].[Text] = [ConsumptionPer100KMs] / 282
End Sub
Run-Time Error 2185: You can't reference a property or method for a control unless the control has focus.

Database is available at!1552, with the name Transport Malta.


Question Info

Last updated January 30, 2019 Views 10,695 Applies to:

As it says in the Help file, "While the control has the focus, the Text property contains the text data currently in the control; the Value property contains the last saved data for the control. When you move the focus to another control, the control's data is updated, and the Value property is set to this new value. The Text property setting is then unavailable until the control gets the focus again." 

Change your code to

Private Sub ConsumptionPer100KMs_AfterUpdate()

     Me![ConsumptionInMilesPerGallon] = Me![ConsumptionPer100KMs] / 282
End Sub
If you're really concerned, you can use
Private Sub ConsumptionPer100KMs_AfterUpdate()
     Me![ConsumptionInMilesPerGallon].Value = Me![ConsumptionPer100KMs].Value / 282
End Sub
(Note that the line [ConsumptionPer100KMs].SetFocus is unnecessary, becuase the control will automatically have focus if the AfterUpdate event is firing: the AfterUpdate event only fires when data is keyed into the control.)
Doug Steele, Microsoft Access MVP

Did this solve your problem?

Sorry this didn't help.

Great! Thanks for marking this as the answer.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this response?

Thanks for your feedback.