Running OnLoad of subform (1 Viewer)

Dreamweaver

Well-known member
Local time
Today, 09:47
Joined
Nov 28, 2005
Messages
2,466
I have been trying to get this working without any luck,Except that is I have to close and open the main form which then updates the controls for the style on the subform but not really happy doing that.

I have tried a number of ways like
Me.Subform.Sourceobject=""
DoCmd.Close "Source Object Form"
Me.Subform.Sourceobject="Source Object Form"
That didn't work

Also Added a public function to the subform and first tried to call the Load_form which didn't work, so I added the call to the style Function which still didn't work

I called the subform function like Form_subform.function I know it was called as put a debug in there.

I suspect I wont get it working any other way other than to do what I doing so thought I would ask

mick
 

theDBguy

I’m here to help
Staff member
Local time
Today, 01:47
Joined
Oct 29, 2018
Messages
21,449
Hi Mick. Did you change the event declaration to Public?
 

Dreamweaver

Well-known member
Local time
Today, 09:47
Joined
Nov 28, 2005
Messages
2,466
Thanks @theDBguy No I called the public function I added and copied all code to that from the load event.

It works when I close the preferences and the code in main control updates the style just can't get it working in a subform.

I've decided to close the preferences screen if they change the style until I can find a way around it.

thanks mick
 

theDBguy

I’m here to help
Staff member
Local time
Today, 01:47
Joined
Oct 29, 2018
Messages
21,449
Thanks @theDBguy No I called the public function I added and copied all code to that from the load event.

It works when I close the preferences and the code in main control updates the style just can't get it working in a subform.

I've decided to close the preferences screen if they change the style until I can find a way around it.

thanks mick
Okay. Let's hope others have more ideas. Good luck!
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 03:47
Joined
Feb 28, 2001
Messages
27,131
Are you saying that you are trying to manually (i.e. using code, not an actual sub-form event) call a sub-form event routine from the main form?

That command MIGHT be something like Me.<sub-form-control>.Form.Form_Load to get there from where it sounds like you are. Or did I misread your question?
 

Dreamweaver

Well-known member
Local time
Today, 09:47
Joined
Nov 28, 2005
Messages
2,466
Yes the code runs as I put a checker in the subforms function I created in the form of a Debug statement, but for some reason the controls are not updated with the new style.

I have just had a thought I added some extra error code to handle something let me check that and I'll come back
 

Dreamweaver

Well-known member
Local time
Today, 09:47
Joined
Nov 28, 2005
Messages
2,466
Sorry to say It was me AGAIN lol

I Added this to the forms as if the db is closed the hidden screen I use seems to get closed first which couses a error
Case 2450
Exit Sub

The form must have been closed when I was trying to test it thats my one for the week lol

I am now using this in the preferences screen
Code:
Public Function AssignToCbo()
Dim CRow As String, MArray() As String
On Error GoTo HandleErr

'Get the Default set style name for the display
    Me![Txt_StyleID] = Forms!frmList!txtX
    Me.Dirty = False
    'DoCmd.Close acForm, Me.Name
    CRow = GetComboRow 'Get the record
     MArray = Split(CRow, ",")
    Me![txtStyle] = MArray(0)
    If IsNothing(MArray(1)) Then
        Me![Pic].Picture = ""
    Else
        Me![Pic].Picture = CurrentProject.Path & "\Style Images\" & MArray(1)
    End If
    'Close The List
    DoCmd.Close acForm, "frmList"
    GetFormDisplay Form, Me![Txt_StyleID] 'You could point this at an employees record on a hidden form Etc.
    'DoCmd.OpenForm "frmPreferences"
    Form_ZfrmPaymentTypeSubform.GetStyle

HandleExit:
    Exit Function
  
HandleErr:
    Select Case Err.Number
        Case Else
            MsgBox Err.Number & vbCrLf & Err.Description
            Resume HandleExit
        Resume
    End Select
End Function

Code:
Public Function GetStyle()
On Error GoTo HandleErr

    Call Form_Load
  
HandleExit:
    Exit Function
  
HandleErr:
    Select Case Err.Number
        Case Else
            MsgBox Err.Number & vbCrLf & Err.Description
            Resume HandleExit
        Resume
    End Select
End Function

Thanks @theDBguy I probably wouldn't have thought of it if you didn't give me a second look at it.
 
Last edited:

theDBguy

I’m here to help
Staff member
Local time
Today, 01:47
Joined
Oct 29, 2018
Messages
21,449
Sorry to say It was me AGAIN lol

I Added this to the forms as if the db is closed the hidden screen I use seems to get closed first which couses a error
Case 2450
Exit Sub

The form must have been closed when I was trying to test it thats my one for the week lol

I am now using this in the preferences screen
Code:
Public Function AssignToCbo()
Dim CRow As String, MArray() As String
On Error GoTo HandleErr

'Get the Default set style name for the display
    Me![Txt_StyleID] = Forms!frmList!txtX
    Me.Dirty = False
    'DoCmd.Close acForm, Me.Name
    CRow = GetComboRow 'Get the record
     MArray = Split(CRow, ",")
    Me![txtStyle] = MArray(0)
    If IsNothing(MArray(1)) Then
        Me![Pic].Picture = ""
    Else
        Me![Pic].Picture = CurrentProject.Path & "\Style Images\" & MArray(1)
    End If
    'Close The List
    DoCmd.Close acForm, "frmList"
    GetFormDisplay Form, Me![Txt_StyleID] 'You could point this at an employees record on a hidden form Etc.
    'DoCmd.OpenForm "frmPreferences"
    Form_ZfrmPaymentTypeSubform.GetStyle

HandleExit:
    Exit Function
 
HandleErr:
    Select Case Err.Number
        Case Else
            MsgBox Err.Number & vbCrLf & Err.Description
            Resume HandleExit
        Resume
    End Select
End Function

Code:
Public Function GetStyle()
On Error GoTo HandleErr

    Call Form_Load
 
HandleExit:
    Exit Function
 
HandleErr:
    Select Case Err.Number
        Case Else
            MsgBox Err.Number & vbCrLf & Err.Description
            Resume HandleExit
        Resume
    End Select
End Function

Thanks @theDBguy I probably wouldn't have thought of it if you didn't give me a second look at it.
Hi Mick. Glad to hear you got it sorted out. Good luck!
 

Users who are viewing this thread

Top Bottom