I need to lock all controls on the main form and a subform when the total of the sub form is 0. The unbound control on the main form holding the value is named sumBalance with the control source picking up the sum of the sub form =Nz([frm_0_accs_fin_trans_journ_subf]![JournalTotal],"")
I have made two alternative VBA codes in the current event on the main form:
If IsNull(Me!sumBalance) Then
Me!fin_trans_id.Locked = False
Me!fin_trans_tstamp.Locked = False
Me!fin_trans_description.Locked = False
Me!frm_0_accs_fin_trans_journ_subf.Locked = False
ElseIf Me!sumBalance < 0 Then
Me!fin_trans_id.Locked = False
Me!fin_trans_tstamp.Locked = False
Me!fin_trans_description.Locked = False
Me!frm_0_accs_fin_trans_journ_subf.Locked = False
ElseIf Me!sumBalance > 0 Then
Me!fin_trans_id.Locked = False
Me!fin_trans_tstamp.Locked = False
Me!fin_trans_description.Locked = False
Me!frm_0_accs_fin_trans_journ_subf.Locked = False
ElseIf Me!sumBalance = 0 Then
Me!fin_trans_id.Locked = True
Me!fin_trans_tstamp.Locked = True
Me!fin_trans_description.Locked = True
Me!frm_0_accs_fin_trans_journ_subf.Locked = True
End If
If Me!sumBalance = 0 Then
Me!fin_trans_id.Locked = True
Me!fin_trans_tstamp.Locked = True
Me!fin_trans_description.Locked = True
Me!frm_0_accs_fin_trans_journ_subf.Locked = True
Else
Me!fin_trans_id.Locked = False
Me!fin_trans_tstamp.Locked = False
Me!fin_trans_description.Locked = False
Me!frm_0_accs_fin_trans_journ_subf.Locked = False
End If
I would have expected both of the VBA codes would result in the main forms controls and the sub form would be unlocked in every other condition than when the control sumBalance = 0.
But when the sumBalance field is empty due to no records in the sub form, the form is also locked preventing from making new records.
What am I missing?
Meby usingWith Me ... End Withwrapper. Use dot instead bang when referencing controls in VBA. Could use textbox and combobox Conditional Formatting to enable/disable. ID controls should probably always be locked or don't even show ID. sumBalance can never be Null because of Nz() function setting control to empty string - an empty string is < 0. In my test, textbox is empty string when subform does not have records. Have you step debugged?booLock = .sumBalance = 0then 4 lines to lock/unlock like.frm_0_accs_fin_trans_journ_subf.Locked = booLock