My access crashes when opening form with Modern Chart and Subform control (1 Viewer)

Babycat

Member
Local time
Today, 14:51
Joined
Mar 31, 2020
Messages
303
Hi everyone
Please help.
On my design:

1. Left-side: a continuous form (SubForm) that shows list of product
2 Right-side (on MainFrm) show product detail of selected product in left-side.
3. Modern chart to show price/qty over time of current product
4. SubForm, MainFrm bound to tblProduct
5. The MainFrm is opened from FormA by a button (attached picture)

Intention: When user clicks on a product row (on continuous form - SubForm) the MainFrm will show that product's detail.

Crash issue:
Happen when combobox = 2 or 3.
Not happend if combobox = 1 or we remove the modern Chart

1774290031386.png


1774290010367.png


Code on FormA to open selected productID (via form open argument)

Code:
Private Sub Btn_ViewProduct_Click()

    DoCmd.OpenForm "MainFrm", , , , , , Combo0 & ""
 
End Sub

Code on the SubForm
Code:
Private Sub Form_Current()
Dim rs As DAO.Recordset

    Set rs = Me.Form.Parent.Form.Recordset
    With rs
            .FindFirst "[ProductID] = " & Txt_ID
            If .NoMatch Then
                MsgBox "Unknow Error - No ProductID " & ProductID & " !"
            End If
    End With
    Set rs = Nothing
 
End Sub

Code:
Private Sub Form_Load()
Dim pID As Long
Dim argStr As String
Dim rs As DAO.Recordset

    If Me.Parent.Form.OpenArgs & "" = "" Then '
        'Dont need to go any record
    Else
        pID = Val(Me.Parent.Form.OpenArgs & "")
        Set rs = Me.Recordset
        With rs
            .FindFirst "[ProductID] = " & pID
            If .NoMatch Then
                MsgBox "Unknow Error - No ProductID " & ProductID & " !"
            End If
        End With
        Set rs = Nothing
    End If
End Sub

My suspect:
- On the FormA, user selected ProductID 2 to view
- MainFrm is loading its control and chart belong to productID 1 (by default sorting)
- at this the, subform forces MainFrm to show productID 2
- The chart of productID 1 is not finish loading yet, --> Access crashes
 

Attachments

Last edited:
FormA attemps to load FormX which does not exist. Opening MainFrm
Code:
'    DoCmd.OpenForm "FormX", , , , , , Combo0 & ""
    DoCmd.OpenForm "MainFrm", , , , , , Combo0 & ""

SubForm Form_Current attempts to search the "MainFrm" recordset after searching in the sub. Why not link in main and search in main.

Your search can be much easer using bookmark.

Code:
        With Me.RecordsetClone
            .FindFirst "[ProductID] = " & pID
            If .NoMatch Then
                MsgBox "Unknow Error - No ProductID " & ProductID & " !"
            Else
                Me.Bookmark = .Bookmark
            End If
        End With

Try adding error trapping and logging, at least debug.print to see the errors as they are raised.
 
Move the load event to the main form.

Code:
Private Sub Form_Load()
    On Error GoTo errForm_Load
    If Me.OpenArgs & "" = "" Then
        'Dont need to go any record
    Else
        With Me.RecordsetClone
            .FindFirst "[ProductID] = " & CLng(Me.OpenArgs)
            If .NoMatch Then
                MsgBox "Unknow Error - No ProductID " & CLng(Me.OpenArgs) & " !"
            Else
                Me.Bookmark = .Bookmark
            End If
        End With
    End If
doneForm_Load:
    Exit Sub
errForm_Load:
    Debug.Print "MainFrm.Form_Load error: " & Err.Number, Err.Description
    Resume doneForm_Load
End Sub

Skip the lookup of main form on 1st call of on_current in the sub-form.

Code:
Private Sub Form_Current()
    On Error GoTo errForm_Current
    Static NextCall As Boolean ' Sub-Form opens before main
    If Not NextCall Then
        NextCall = True
    Else
        With Me.Form.Parent.Form.RecordsetClone
            .FindFirst "[ProductID] = " & Txt_ID
            If .NoMatch Then
                MsgBox "Unknow Error - No ProductID " & ProductID & " !"
            Else
                Me.Form.Parent.Form.Bookmark = .Bookmark
            End If
        End With
    End If
doneForm_Current:
    Exit Sub
errForm_Current:
    Debug.Print "SubForm.Form_Current error: " & Err.Number, Err.Description
    Resume doneForm_Current
End Sub
 
It's working bro,
Two consecutive searches in sub-form load and current event might causes main form overloaded especially it contains modern chart. So we skip the first call then it works

btw: These two below code snipes work but any performance difference?


Code:
        With Me.RecordsetClone
            .FindFirst "[ProductID] = " & CLng(Me.OpenArgs)
            If .NoMatch Then
            Else
                Me.Bookmark = .Bookmark
            End If
        End With

Code:
        With Me.Recordset
            .FindFirst "[ProductID] = " & CLng(Me.OpenArgs)
        End With

I noticed they jump to exactly searched ProductID
 
Last edited:
Move the load event to the main form.
Hi RonPaii

I found an issue here. If we skip the first time of subform's current event, then the mainform and subform will not be synched same record ID
1774317281423.png
 
here you may try to test.
It is not the modern chart's fault.
it is because it is creating an Endless loop.
 

Attachments

Last edited:

Users who are viewing this thread

Back
Top Bottom