Solved Referring to a control on a subform from the parent form. (1 Viewer)

AlliCarr

Member
Local time
Today, 14:18
Joined
Feb 19, 2024
Messages
35
Hoping someone can help.

I have a number of checklists in my database which I have built using the fab tutorials from Nifty Access. All my forms have the fields disabled until the user edits this record via the click of a command button. I've included this to prevent unintentional editing and to make it clearer to the user which fields they can and cannot edit.

With this in mind, the controls which contain the checklist subforms are also disabled until the edit command button is clicked when the use can then check whichever boxes they need. However, there's one of my checklists that doesn't enable when the edit command button is clicked. The code behind the button is below:

Code:
Private Sub Edit_Click()
On Error GoTo ErrorHandler

EditForm Me

Me.GrantOutcomesDataSubWindow.Form!Selected.Enabled = True

AssessmentFields Me

'Enables payment fields if payment not yet authorised
    If Me.Recommendation = "Approval" And IsNull(Me.FirstAuthorisation) Then

        Me.AccountName.Enabled = True
        Me.AccountNumber.Enabled = True
        Me.SortCode.Enabled = True
        Me.BuildingSocietyRef.Enabled = True

    End If

'If payment has been authorised but not paid, enable payment date control and save button
    If IsNull(Me.PaymentDate) And Not IsNull(Me.FinalAuthorisationDate) And _
    Me.Recommendation = "Approval" Then

        Me.PaymentDate.Enabled = True
        Me.SavePayDate.Enabled = True

    End If

'enables null payment authorisation fields only depending on user
    If Forms![homepagef]!AccessID = 1 Or Forms![homepagef]!AccessID = 2 Then
        If Me.Recommendation = "Approval" Then
            If IsNull(Me.FirstAuthorisation) Then
                If IsNull(Me.FirstAuthorisationDate) Then
                    If IsNull(Me.FinalAuthorisation) Then

                        Me.FirstAuthorisation.Enabled = True
                        Me.FirstAuthorisationDate.Enabled = True
                        Me.FinalAuthorisation.Enabled = True
                        Me.SaveFirstAuth.Enabled = True

                    End If

                End If

            End If

        End If

    End If


'enables null final authorisation fields only dependent on user
    If Forms![homepagef]!AccessID = 5 Or Forms![homepagef]!AccessID = 1 Then
        If Me.Recommendation = "Approval" Then
            If IsNull(Me.FinalAuthorisationDate) Then

            Me.FinalAuthorisationDate.Enabled = True
            Me.SaveFinalAuth.Enabled = True

            End If

        End If

    End If

'enables SMT approval fields if funding requested is up to £2k
    If Me.Programme = "Wales fast track" Or Me.Programme = "Wales kit grants" _
    Or Me.Programme = "England £2K" Then
        If Forms![homepagef]!AccessID = 5 Then
            If IsNull(Me.SMTApprovedBy) Then
                If IsNull(Me.ApprovalDate) Then

                Me.SMTApprovedBy.Enabled = True
                Me.ApprovalDate.Enabled = True
                Me.TrusteeApproval.Enabled = False
                Me.MinuteReference.Enabled = False

                End If

            End If

        End If

    End If

'enables trustee approval fields if funding requested is over £2k
    If Me.Programme = "England £10K" Or Me.Programme = "Wales main grants" Then
        If Me.TrusteeApproval = 0 Then
            If IsNull(Me.MinuteReference) Then

            Me.TrusteeApproval.Enabled = True
            Me.MinuteReference.Enabled = True
            Me.SMTApprovedBy.Enabled = False
            Me.ApprovalDate.Enabled = True

            End If

        End If

    End If

Exit Sub

ErrorHandler:
    Dim msg As String
    msg = Err.Number & ":" & Err.Description
    MsgBox msg

End Sub

The strange thing is that the Me.GrantOutcomesDataSubWindow.Form!Selected.Enabled = True line of code is exactly the same (with the exception of the name of the sub window controls) in another form with another 4 checklists and this works perfectly.

I did wonder if it was due to the other code included in the on click event but the above line of code actually works in a previous copy of the database and the only addition in this set of code is the AssessmentFields Me line which calls this module:

Code:
Public Sub AssessmentFields(frm As Access.Form)

If frm.Programme = "England £10K" Then
frm.MainGrants.Enabled = False
frm.StateAid.Enabled = False
frm.Sustainability.Enabled = False
frm.SustainabilityScore.Enabled = False
frm.ManagementDeliverability.Enabled = False
frm.MDScore.Enabled = False
frm.Risk.Enabled = False
frm.RiskScore.Enabled = False
End If

If frm.Programme = "England £2K" Then
frm.MainGrants.Enabled = False
frm.StateAid.Enabled = False
frm.AreaScore.Enabled = False
frm.Sustainability.Enabled = False
frm.SustainabilityScore.Enabled = False
frm.ManagementDeliverability.Enabled = False
frm.MDScore.Enabled = False
frm.Risk.Enabled = False
frm.RiskScore.Enabled = False
End If

End Sub

This works fine too when the edit button is clicked and it's also very similar to the other code in the version of the database that works so I'm a little stumped.

Hope someone can help.
Kind regards
Allison
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 09:18
Joined
May 21, 2018
Messages
8,751
Not very helpful.
What is the error?
What line is the error?
I have a number of checklists in my database
My first guess based on that is you copied and pasted a subform control. If that is the case there is a good chance that the subform control no longer has the name of the subform but more like "Child0"
verify that Me.GrantOutcomesDataSubWindow exists or has a new name.
Easy test.
Type Me.Gr... and see if intellisense comes up.
 

AlliCarr

Member
Local time
Today, 14:18
Joined
Feb 19, 2024
Messages
35
Not very helpful.
What is the error?
What line is the error?

My first guess based on that is you copied and pasted a subform control. If that is the case there is a good chance that the subform control no longer has the name of the subform but more like "Child0"
verify that Me.GrantOutcomesDataSubWindow exists or has a new name.
Easy test.
Type Me.Gr... and see if intellisense comes up.
There is no error, even when I disable error handling, the checkbox control in the subform just doesn't enable like it should.

The subform control wasn't copied either as it's a separate checklist altogether with a separate table and subform and I have already checked that the name is correct. (The intellisense does come up).
 

AlliCarr

Member
Local time
Today, 14:18
Joined
Feb 19, 2024
Messages
35
So it turns out I'm an absolute numpty!

After deleting the checklist subform and setting it up again and it still not working, I figured the issue could be to do with the parent form and it was. Allow Edits was set to 'No' on the parent form!! Changed it to 'Yes' and it works fine! I've no idea when and why I changed Allow Edits to no but I must have done at some point. :rolleyes:

I suppose at least I won't do that again! 😅

Thanks @MajP for looking at it for me though.
 

Users who are viewing this thread

Top Bottom