I have a form containing a subform which is used to enter payment requisitions in. I have the form opening from a VB button on a menu form. I am trying to set the form and subform to editable if opened via a Button with onclick Event as shown.
or Read only if entered through another button.
I have some VBA in the OnLoad Event which seems to cause the acFormreadOnly to be disabled.
When I click on the subform and then back to the main form, the ReadOnly is working.
Some of the code that I have in the OnLoad event
I have tried adding to the OnActivate event using the "ReadOnly" Argument attached to the button.
I have been wracking my brain and scouring the internet for a solution and have drawn a blank. I hope that I have missed something small and fundamental that I will learn from.....!
Thanks for your help.
Gary
Code:
Private Sub btnNewPayment_Click() DoCmd.OpenForm "frmPayments", , , , acFormAdd End Sub
or Read only if entered through another button.
Code:
Private Sub btnAllPayments_Click() DoCmd.OpenForm "frmPayments", , , , acFormReadOnly, acDialog, "ReadOnly" End Sub
When I click on the subform and then back to the main form, the ReadOnly is working.
Some of the code that I have in the OnLoad event
Code:
Private Sub Form_Load()
If UserLevel() >= 4 Then ' UseLevel is a custom Function
Me.lblAuthorisedForPayment.Visible = True
Me.lblAuthorisedBy.Visible = True
Me.lblTimeDate.Visible = True
Me.AuthorisedForPayment.Visible = True
Me.AuthorisedBy.Visible = True
Me.TimeDateAuthorised.Visible = True
Else
Me.lblAuthorisedForPayment.Visible = False
Me.lblAuthorisedBy.Visible = False
Me.lblTimeDate.Visible = False
Me.AuthorisedForPayment.Visible = False
Me.AuthorisedBy.Visible = False
Me.TimeDateAuthorised.Visible = False
End If
Me.tboLastExRate = Format(CurrentDb.OpenRecordset("qryLastDateCurrencyImported").Fields(0), "dd mmm yyyy")
DoCmd.GoToControl "PaymentID"
End Sub
Code:
Private Sub Form_Activate()
If Me.OpenArgs = "ReadOnly" Then
Me.AllowEdits = False
Me.AllowDeletions = False
Me.AllowAdditions = False
'Name the control, containing your subform
Me.sub_frmPaymentDetails.Form.AllowEdits = False
Me.sub_frmPaymentDetails.Form.AllowDeletions = False
Me.sub_frmPaymentDetails.Form.AllowAdditions = False
End If
End Sub
Thanks for your help.
Gary
Comment