Run-time error 424, Object required

Wappervliegje

Registered User.
Local time
Today, 09:45
Joined
Nov 11, 2014
Messages
23
Dear people,

I hope that you can help me with my problem. I have made a code (see below) to run a code for all subforms. But I get always "Run-time error 424, Object required". I don't know why this code can find no one of all subforms? I thought that if I change this "With SubForm(Sequence)" into "With "." & SubForm(Sequence)", this problem is then going. But no result... :confused:

Code:
Private Sub Form_Current()
    Dim DLookUpSID As String
    Dim SubForm As Variant
    Dim Sequence As Long
        DLookUpSID = DLookup("Security_ID", "tbl_Security_Level", "[Security_ID]=" & _
                    Nz(DLookup("User_Security_ID", "tbl_Users", "[User_Name]='" & VBA.Environ("USERNAME") & "'"), "6") & "")
        SubForm = Array( _
                ".fsub_Bestellingen", _
                ".fsub_Uitvullen", _
                ".fsub_Titratie", _
                ".fsub_Verlopen_Antilichamen", _
                ".fsub_Status_Bestellingen", _
                ".fsub_Panels")
            With Me
                If DLookUpSID <= 2 Then
                    For Sequence = 0 To 3
                       With SubForm(Sequence)
                            .Locked = False
                            .Form.cmd_Add.Enabled = True
                            .Form.cmd_Undo.Enabled = True
                            .Form.cmd_Remove.Enabled = True
                            .Form.cmd_Save.Enabled = True
                        End With
                    Next
                Else
                    For Sequence = 0 To 3
                       With SubForm(Sequence)
                            .Locked = true
                            .Form.cmd_Add.Enabled = False
                            .Form.cmd_Undo.Enabled = False
                            .Form.cmd_Remove.Enabled = False
                            .Form.cmd_Save.Enabled = False
                        End With
                    Next
                End If
            End With

With kindly regards! Wappervliegje! :D
 
In which code line do you get the error?
Could it be because you are missing a .
Code:
With Me
    If DLookUpSID <= 2 Then
       For Sequence = 0 To 3
           With [B][SIZE=4][COLOR=Red].[/COLOR][/SIZE][/B]SubForm(Sequence)
 
Hi JHB,

Thank your for your reaction and hint! I've trying to do what you'd advised to me, but it doesn't working. Because the VBA can't find the subforms, only zero. I was puzzling further with your . and now I've finally found the solution: .Form(SubForm(Sequence)). The subforms are now found. :D
 
Okay - then it was anyway something with the dot. :)
 
Yeah, you've right! Ow, I'd read my posts at the other forum that the best solution is: .Controls(Subform(sequence)). I want to share this information with this forum. :D
 

Users who are viewing this thread

Back
Top Bottom