Chaining Forms lockup (1 Viewer)

ClaraBarton

Registered User.
Local time
Today, 11:47
Joined
Oct 14, 2019
Messages
479
I've added Pat Hartman's code for chaining forms. Everything was going merrily along until suddenly things were locking up and I had to use task manager to get out of Access. After much time I think I traced the problem to this code:
Code:
Private Sub Form_Unload(Cancel As Integer)
    Call sUnload(Me)
End Sub
I can't really put my finger on it but I notice in the locals window this:
1681243316074.png

I went back to the chaining forms example and I notice that her's shows the same thing. It doesn't seem to be an error, only shows in the locals window. Is this typical? If I comment out the unload sub I don't get locked out but of course... it doesn't work.
 

jdraw

Super Moderator
Staff member
Local time
Today, 14:47
Joined
Jan 23, 2006
Messages
15,393
Can you post your database or enough of it (event code) to show the issue and any messages/errors?
 

ClaraBarton

Registered User.
Local time
Today, 11:47
Joined
Oct 14, 2019
Messages
479
You can chain through the forms fine but if you stop and open any one in design view it will lock up.
 

Attachments

  • SampleLibrary.accdb
    5.7 MB · Views: 73

MajP

You've got your good things, and you've got mine.
Local time
Today, 14:47
Joined
May 21, 2018
Messages
8,556
I took a look at it and cannot figure it out. I tried to debug and clean up some of the code, and have no idea what is going on.
For others the bottom line is if you go into design mode of a form the application locks ups. The OP is correct in that if you remove the "chaining" code this does not happen.

here is the code
Code:
Option Compare Database
Option Explicit
'Pat Hartman; chaining forms
Global gFrmName As String

Public Sub sOpenForm(frm As Form, frmName As String, intID As Integer)
    Dim strLongFormName As String
    Dim strWhere As String
           
    frm.Visible = False 'calling form
    strLongFormName = "Forms!" & frm.Name
          If intID > 0 Then
            strWhere = "[BookID] = " & intID

            DoCmd.OpenForm frmName, _
                WhereCondition:=strWhere, _
                OpenArgs:=strLongFormName
   
        Else
            DoCmd.OpenForm frmName, _
               OpenArgs:=strLongFormName
        End If
   
End Sub

Public Sub sUnload(frm As Form)
    Dim strShortFormName As String

    gFrmName = frm.Name
    If IsNull(frm.OpenArgs) Then
        DoCmd.OpenForm "frmMenu", acNormal, , , acFormEdit, acDialog
       
    Else
        strShortFormName = Mid(frm.OpenArgs, InStrRev(frm.OpenArgs, "!") + 1)
        DoCmd.OpenForm strShortFormName
    End If
End Sub

Public Sub sActivate(frm As Form)
    frm!txtOpenedBy = gFrmName
    gFrmName = frm.Name
End Sub

When a form loads the sActivate is called when it unloads the sUnload is called.

When you go into design view I assume that will trigger the form's unload event and thus the sUnload method.
 
Last edited:

KitaYama

Well-known member
Local time
Tomorrow, 03:47
Joined
Jan 6, 2022
Messages
1,567
For others the bottom line is if you go into design mode of a form the application locks ups.
Changing the Modal property of the frmMenu to NO, solves the problem.
 
Last edited:

Pat Hartman

Super Moderator
Staff member
Local time
Today, 14:47
Joined
Feb 19, 2002
Messages
43,392
I would be careful about how many forms get left open. And you don't want to have any given form opened multiple times
 

Users who are viewing this thread

Top Bottom