can't reference object unless focus is set ?

qwertyjjj

Registered User.
Local time
Today, 02:46
Joined
Aug 8, 2006
Messages
262
Private Sub txt_Actual_Change()
Dim sSQL As String
sSQL = "UPDATE TableA SET Actual = " & Me.txt_Actual.Text & ", Target = " & Me.txt_Target.Text & "WHERE FormName = 'TestForm'"
DoCmd.RunSQL (sSQL)
End Sub

Every time I load the form, I get an error message saying I can't reference the object unless it's focus is set.
Why do I have to set the focus on the control box? I don't think you have to do this in nomrla visual basic ?

It highlights the sSQL= line. I presume it is the txt_Actual.Text that is causing the problem ?
 
In order to reference the .Text property of a control, the control must have the focus. This focus requirement is unnecessary to reference the .Value property, which is the default property. Either Me.txt_Target.Value or Me.txt_Target will work.
 

Users who are viewing this thread

Back
Top Bottom