Code to disable/enable fields not working for a new record

JamesWB

Registered User.
Local time
Today, 06:36
Joined
Jul 14, 2014
Messages
70
I have some code like this that sets some fields up to be disabled when the form loads, then enables them when a combo box ('Type') is selected to 'Instrument'. This works fine as far as it goes, but if the user has selected 'Instrument' and then goes to a new record, the fields remain enabled.

Private Sub Form_Load()
Me.CalibrationTolerance.Enabled = False
Me.AcceptanceLimit.Enabled = False
End Sub

Private Sub Type_AfterUpdate()
If Me.Type.Value = "Instrument" Then
If Me.NewRecord = True Then
Me.CalibrationTolerance.Enabled = True
Me.AcceptanceLimit.Enabled = True
Else: Me.CalibrationTolerance.Enabled = False
Me.AcceptanceLimit.Enabled = False
Me.ActionLimit.Enabled = False

End If
End If
End Sub


I've looked this up and it appears I need to use the property Form.NewRecord, but nothing I do seems to make it work. I am a bit shaky with VBA still, is there something fundamental I am missing?

Thanks for any help! :)
 
I suggest you put some code in the forms On Current event to set the field properties, depending on the value of the combo box
 
I suggest you put some code in the forms On Current event to set the field properties, depending on the value of the combo box

Ahh... OnCurrent is the relevant property for a new record then? Thanks.
 
Ahh... OnCurrent is the relevant property for a new record then? Thanks.
Not exactly. The OnCurrent event fires every time a record is accessed. This is the best place to put your your code that sets the text box values instead of the On Load event which only fires when the form is first opened.
 
The code for the On Current event would be the same as the code you have in the After Update event of the combo box. Sorry, should have made this clear in last post.
 
The code for the On Current event would be the same as the code you have in the After Update event of the combo box. Sorry, should have made this clear in last post.

That's very helpful, thanks a lot.

So I don't need the Form OnLoad bit at all? OnCurrent covers that?
 

Users who are viewing this thread

Back
Top Bottom