I have an Access database with a data-bound form. The database is in the old .mdb format, but I'm using it with Access 2010. I want code to run on the GotFocus event of certain controls (combo boxes and text boxes) that sets the control value to a default
if it's not already set. Here's what I've tried:
Private Sub Office_Unit_GotFocus()
If Me.Office_Unit.DefaultValue <> "" And IsNull(Me.Office_Unit.Value) Then
Me.Office_Unit = Me.Office_Unit.DefaultValue
End If
End Sub
If I'm in an existing (previously saved) record, this works correctly. However, when I'm in a new record, I get the following error message:
Run-time error '2447': There is an invalid use of the dot (.) or ! operator or parentheses.
If I debug at this point, I'm able to retrieve the DefaultValue property of the control
Me.Office_Unit.DefaultValue
But if I ask the debugger for Me.Office_Unit.Value or just Me.Office_Unit, I get the error message mentioned above.
I've come up with a reasonable workaround for this issue (it's not generally useful, but it works well enough in this particular application). However, I'd love to understand what's going on here and how to fix it properly.