none
Access 2007 Just shuts down.

    Question

  • I have two similar forms that do different tasks using a timer event.  I have a main form that opens each of the other forms using a command button.

    One Main form button code is: " DoCmd.OpenForm "SerialPlusCreateQuickFlowRecordForm", , , , , acHidden"

    This button works fine, the form opens and the associated timer event works just fine.

    The other Main form button code is: DoCmd.OpenForm "SerializationGeneratorTimerForm", , , , , acHidden"

    The second form, causes Access to shut down without any messages as to why.  If I remove the "acHidden" option, it works fine. 

    I know that the docmd.openform line is the one it fails on because I set breakpoints to step through the code, and that is the line it crashes on.

    Any ideas as to why and/or troubleshooting suggestions?


    • Edited by tkosel Saturday, January 19, 2013 11:27 PM
    Saturday, January 19, 2013 10:52 PM

All replies

  • Do you have any code in any form event of the second form?

    Bob Larson, Access MVP 2008, 2009, 2011

    Sunday, January 20, 2013 12:40 AM
  • Bob,

    Yes, the following load event.

      Private Sub Form_Load()
        
        'set the timer interval here
        
        Me.Station = V_StationName
        If V_StationName = "Station1" Then
            Me.RecordSource = "SELECT SerializationGeneratorTableStation1.FamilyOfPartsNumber, SerializationGeneratorTableStation1.LotNumber, SerializationGeneratorTableStation1.SerialNumber, SerializationGeneratorTableStation1.RecordUsedFlag, SerializationGeneratorTableStation1.[Date/TimeUsed]FROM SerializationGeneratorTableStation1;"
        ElseIf V_StationName = "Station2" Then
            Me.RecordSource = "SELECT SerializationGeneratorTableStation2.FamilyOfPartsNumber, SerializationGeneratorTableStation2.LotNumber, SerializationGeneratorTableStation2.SerialNumber, SerializationGeneratorTableStation2.RecordUsedFlag, SerializationGeneratorTableStation2.[Date/TimeUsed]FROM SerializationGeneratorTableStation2;"
        End If
        
        'Forms![SerializationGeneratorTimerForm].TimerInterval = DLookup("[SerialPlusVariableTimerSeconds]", "Utility_Table") * 1000
        Me.TimerInterval = DLookup("[SerialPlusVariableTimerSeconds]", "Utility_Table") * 1000
     
    End Sub

    And a timer event.

    Private Sub Form_Timer()
        
        Forms!SerializationGeneratorMainMenu![WaitMessage].Visible = True
        
        Forms!SerializationGeneratorMainMenu![WaitMessage].BackColor = RGB(&H22, &HB1, &H4C)
        If Forms!SerializationGeneratorMainMenu![WaitMessage].Caption = "Ready!" Then
            Forms!SerializationGeneratorMainMenu![WaitMessage].Caption = "Still Ready!"
        Else
            Forms!SerializationGeneratorMainMenu![WaitMessage].Caption = "Ready!"
        End If
        
        Dim V_Partnumber, V_PartNumberToLookup, V_StringLength, V_PrefixCharLen, V_MaxSerialNoLen, V_LeadingZeros, V_Value
        
        If Me.RecordUsedFlagCheck = -1 Then
            Me.TimerInterval = 0 'turn off the timer
            Forms!SerializationGeneratorMainMenu![WaitMessage].BackColor = RGB(&HED, &H1C, &H24)   'Red
            Forms!SerializationGeneratorMainMenu![WaitMessage].Caption = "Please Wait . ." & vbCr & vbLf & "Processing . ."
            
            DoCmd.Close acForm, "SerializationGeneratorTimerForm"
            
            DoCmd.SetWarnings False
            If V_StationName = "Station1" Then
                DoCmd.OpenQuery "QueryToAppendSerializationGeneratorDateToLogTableStation1" 'Flag must be set to true
                'Me.Dirty = False
                DoCmd.OpenQuery "SeralizationGeneratorQueryToDeleteAllDataStation1"
            ElseIf V_StationName = "Station2" Then
                DoCmd.OpenQuery "QueryToAppendSerializationGeneratorDateToLogTableStation2" 'Flag must be set to true
                'Me.Dirty = False
                DoCmd.OpenQuery "SeralizationGeneratorQueryToDeleteAllDataStation2"
            End If
            DoCmd.SetWarnings True
        
        
            'then create a new record
            ' ======================= Create a new record here =========================================
        
            V_StringLength = InStr(1, Forms!SerializationGeneratorMainMenu.PartNumber, "-")
            If V_StringLength = 0 Then 'There is no dash in the string
                'Forms!SerializationGeneratorMainMenu.FamilyOfPartsNumber = DLookup("[PartNumber]", "SerializationGeneratorPartNumbersTable", "[PartNumber] = " & """" & Forms!SerializationGeneratorMainMenu.PartNumber & """")
                V_PartNumberToLookup = Forms!SerializationGeneratorMainMenu.FamilyOfPartsNumber
            ElseIf V_StringLength > 0 Then 'There is a dash in the string
                V_PartNumberToLookup = Left(Forms!SerializationGeneratorMainMenu.PartNumber, V_StringLength - 1) & "-XXX"
                'Forms!SerializationGeneratorMainMenu.FamilyOfPartsNumber = Left(Forms!SerializationGeneratorMainMenu.PartNumber, V_StringLength - 1)
            End If
            
            'Forms!SerializationGeneratorMainMenu.PrefixCharacter = DLookup("[PrefixCharacter]", "SerializationGeneratorPartNumbersTable", "[PartNumberCharFormat] = " & """" & V_PartNumberToLookup & """")
            'Forms!SerializationGeneratorMainMenu.SerialNoLength = Len(DLookup("[MaxSerialNumber]", "SerializationGeneratorPartNumbersTable", "[PartNumberCharFormat] = " & """" & V_PartNumberToLookup & """"))
            Forms!SerializationGeneratorMainMenu.MaxSerialNoUsed = DMax("[SerialNumberAssigned]", "SerializationGeneratorLogTable", "[FamilyOfPartsNumber] = " & """" & V_PartNumberToLookup & """")
            V_PrefixCharLen = Len(Forms!SerializationGeneratorMainMenu.PrefixCharacter)
            V_PrefixCharLen = Nz(V_PrefixCharLen, 0)
            V_MaxSerialNoLen = Len(Forms!SerializationGeneratorMainMenu.MaxSerialNoUsed)
            'Forms!SerializationGeneratorMainMenu.SerialNumberSeed = DLookup("[SerialNumberSeed]", "SerializationGeneratorPartNumbersTable", "[PartNumberCharFormat] = " & """" & V_PartNumberToLookup & """")
            
            V_NullTest = IsNull(Forms!SerializationGeneratorMainMenu.MaxSerialNoUsed)
            If V_NullTest = False Then
                V_Value = Val(Mid(Forms!SerializationGeneratorMainMenu.MaxSerialNoUsed, V_PrefixCharLen + 1, V_MaxSerialNoLen - V_PrefixCharLen)) + 1
            Else
                V_Value = 0
            End If
            If V_Value < Val(Forms!SerializationGeneratorMainMenu.SerialNumberSeed) Then 'Start serial number here
                V_Value = Forms!SerializationGeneratorMainMenu.SerialNumberSeed
            Else 'Seed is not needed
                Forms!SerializationGeneratorMainMenu.SerialNumberSeed.Visible = False
            End If
            
            ' ========================== Section for 6 digit serial number ===============================
            If Forms!SerializationGeneratorMainMenu.SerialNoLength = 6 Then
                If V_Value < 10 Then
                    V_LeadingZeros = String(Forms!SerializationGeneratorMainMenu.SerialNoLength - 1, "0")
                ElseIf V_Value < 100 Then
                    V_LeadingZeros = String(Forms!SerializationGeneratorMainMenu.SerialNoLength - 2, "0")
                ElseIf V_Value < 1000 Then
                    V_LeadingZeros = String(Forms!SerializationGeneratorMainMenu.SerialNoLength - 3, "0")
                ElseIf V_Value < 10000 Then
                    V_LeadingZeros = String(Forms!SerializationGeneratorMainMenu.SerialNoLength - 4, "0")
                ElseIf V_Value < 100000 Then
                    V_LeadingZeros = String(Forms!SerializationGeneratorMainMenu.SerialNoLength - 5, "0")
                Else
                    V_LeadingZeros = Null
                End If
            End If
            ' ===========================================================================================
        
            ' ========================== Section for 7 digit serial number ===============================
            If Forms!SerializationGeneratorMainMenu.SerialNoLength = 7 Then
                If V_Value < 10 Then
                    V_LeadingZeros = String(Forms!SerializationGeneratorMainMenu.SerialNoLength - 1, "0")
                ElseIf V_Value < 100 Then
                    V_LeadingZeros = String(Forms!SerializationGeneratorMainMenu.SerialNoLength - 2, "0")
                ElseIf V_Value < 1000 Then
                    V_LeadingZeros = String(Forms!SerializationGeneratorMainMenu.SerialNoLength - 3, "0")
                ElseIf V_Value < 10000 Then
                    V_LeadingZeros = String(Forms!SerializationGeneratorMainMenu.SerialNoLength - 4, "0")
                ElseIf V_Value < 100000 Then
                    V_LeadingZeros = String(Forms!SerializationGeneratorMainMenu.SerialNoLength - 5, "0")
                ElseIf V_Value < 1000000 Then
                    V_LeadingZeros = String(Forms!SerializationGeneratorMainMenu.SerialNoLength - 6, "0")
                Else
                    V_LeadingZeros = Null
                End If
            End If
            ' ===========================================================================================
            
            ' ============================= Section for 8 digit serial number =============================
            If Forms!SerializationGeneratorMainMenu.SerialNoLength = 8 Then
                If V_Value < 10 Then
                    V_LeadingZeros = String(Forms!SerializationGeneratorMainMenu.SerialNoLength - 1, "0")
                ElseIf V_Value < 100 Then
                    V_LeadingZeros = String(Forms!SerializationGeneratorMainMenu.SerialNoLength - 2, "0")
                ElseIf V_Value < 1000 Then
                    V_LeadingZeros = String(Forms!SerializationGeneratorMainMenu.SerialNoLength - 3, "0")
                ElseIf V_Value < 10000 Then
                    V_LeadingZeros = String(Forms!SerializationGeneratorMainMenu.SerialNoLength - 4, "0")
                ElseIf V_Value < 100000 Then
                    V_LeadingZeros = String(Forms!SerializationGeneratorMainMenu.SerialNoLength - 5, "0")
                ElseIf V_Value < 1000000 Then
                    V_LeadingZeros = String(Forms!SerializationGeneratorMainMenu.SerialNoLength - 6, "0")
                ElseIf V_Value < 10000000 Then
                    V_LeadingZeros = String(Forms!SerializationGeneratorMainMenu.SerialNoLength - 7, "0")
                Else
                    V_LeadingZeros = Null
                End If
            End If
            ' ===============================================================================================
                    
            ' ============================= Section for 9 digit serial number =============================
            If Forms!SerializationGeneratorMainMenu.SerialNoLength = 9 Then
                If V_Value < 10 Then
                    V_LeadingZeros = String(Forms!SerializationGeneratorMainMenu.SerialNoLength - 1, "0")
                ElseIf V_Value < 100 Then
                    V_LeadingZeros = String(Forms!SerializationGeneratorMainMenu.SerialNoLength - 2, "0")
                ElseIf V_Value < 1000 Then
                    V_LeadingZeros = String(Forms!SerializationGeneratorMainMenu.SerialNoLength - 3, "0")
                ElseIf V_Value < 10000 Then
                    V_LeadingZeros = String(Forms!SerializationGeneratorMainMenu.SerialNoLength - 4, "0")
                ElseIf V_Value < 100000 Then
                    V_LeadingZeros = String(Forms!SerializationGeneratorMainMenu.SerialNoLength - 5, "0")
                ElseIf V_Value < 1000000 Then
                    V_LeadingZeros = String(Forms!SerializationGeneratorMainMenu.SerialNoLength - 6, "0")
                ElseIf V_Value < 10000000 Then
                    V_LeadingZeros = String(Forms!SerializationGeneratorMainMenu.SerialNoLength - 7, "0")
                ElseIf V_Value < 100000000 Then
                    V_LeadingZeros = String(Forms!SerializationGeneratorMainMenu.SerialNoLength - 8, "0")
                Else
                    V_LeadingZeros = Null
                End If
            End If
            ' ==============================================================================================
                    
            ' ============================= Section for 10 digit serial number =============================
            If Forms!SerializationGeneratorMainMenu.SerialNoLength = 10 Then
                If V_Value < 10 Then
                    V_LeadingZeros = String(Forms!SerializationGeneratorMainMenu.SerialNoLength - 1, "0")
                ElseIf V_Value < 100 Then
                    V_LeadingZeros = String(Forms!SerializationGeneratorMainMenu.SerialNoLength - 2, "0")
                ElseIf V_Value < 1000 Then
                    V_LeadingZeros = String(Forms!SerializationGeneratorMainMenu.SerialNoLength - 3, "0")
                ElseIf V_Value < 10000 Then
                    V_LeadingZeros = String(Forms!SerializationGeneratorMainMenu.SerialNoLength - 4, "0")
                ElseIf V_Value < 100000 Then
                    V_LeadingZeros = String(Forms!SerializationGeneratorMainMenu.SerialNoLength - 5, "0")
                ElseIf V_Value < 1000000 Then
                    V_LeadingZeros = String(Forms!SerializationGeneratorMainMenu.SerialNoLength - 6, "0")
                ElseIf V_Value < 10000000 Then
                    V_LeadingZeros = String(Forms!SerializationGeneratorMainMenu.SerialNoLength - 7, "0")
                ElseIf V_Value < 100000000 Then
                    V_LeadingZeros = String(Forms!SerializationGeneratorMainMenu.SerialNoLength - 8, "0")
                ElseIf V_Value < 1000000000 Then
                    V_LeadingZeros = String(Forms!SerializationGeneratorMainMenu.SerialNoLength - 9, "0")
                Else
                    V_LeadingZeros = Null
                End If
            End If
            ' ===========================================================================================
        Else
            GoTo Done
        End If
        ' ****************************
        
        Forms!SerializationGeneratorMainMenu.SerialNoToUse = Forms!SerializationGeneratorMainMenu.PrefixCharacter & V_LeadingZeros & V_Value
        
        If DLookup("[SerialNumberAssigned]", "SerializationGeneratorLogTable", "[FamilyOfPartsNumber] = " & """" & Forms!SerializationGeneratorMainMenu.FamilyOfPartsNumber & """") = Forms!SerializationGeneratorMainMenu.SerialNoToUse Then 'That serial number already exists, there is a problem
            MsgBox "That serial number has already been used, cannot continue." & vbCr & vbLf & "Contact the IT department with this information for assistance.", , "Cannot use that serial number."
            Forms!SerializationGeneratorMainMenu.SerialNoToUse = ""
            GoTo Done
        End If
        
        'Forms!SerializationGeneratorMainMenu.LotNumber.Requery
        DoCmd.SetWarnings False
        If V_StationName = "Station1" Then
            DoCmd.OpenQuery "QueryToCreateSerializationGeneratorDataStation1"
        ElseIf V_StationName = "Station2" Then
            DoCmd.OpenQuery "QueryToCreateSerializationGeneratorDataStation2"
        End If
        DoCmd.SetWarnings True
        
        ' ===================== end of section to create a new record  ==================================

        DoCmd.OpenForm "SerializationGeneratorTimerForm" ', , , , , acHidden
        Forms![SerializationGeneratorTimerForm].TimerInterval = DLookup("[SerialPlusVariableTimerSeconds]", "Utility_Table") * 1000
           
    Done:
     
    End Sub

    However, these events run fine when the acHidden property is removed.  I realize this is  probably too much code, but it works when the form isn't hidden.

    Sunday, January 20, 2013 4:44 AM
  • Hi tkosel,

    Welcome to the MSDN forum.

    I'm trying to involve some senior engineers into the issue and it takes some time. Your patience will be greatly appreciated.

    Have a nice day.


    Yoyo Jiang[MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, January 23, 2013 11:05 AM
    Moderator
  • ....
    Friday, January 25, 2013 3:13 PM
  • Hi TKosel,

    The first thing I noticed is that in your timer event you are attempting to make a field visible on a hidden form. It would not surprise me that this could cause problems with Visual Basic and by extension Access.

    Private Sub Form_Timer()
        Forms!SerializationGeneratorMainMenu![WaitMessage].Visible = True

    My first suggestion is to comment out that line of code to see if that "fixes" the issue.

    If it doesn't I would recommend putting break points in the Form_Load, Form_Timer and any other form events you have on the "SerializationGeneratorTimerForm" form.
    If the code stops on a break point you should be able to step through and hopefully provide more information.
    If Access shuts down before hitting a break point then I would recommend using the VBA command "SaveAsText" and "LoadFromText" to build a new copy of the form on the chance there may be some level of corruption.

    Best Regards,

    Donald M.
    Microsoft Online Community Support
    --------------------------------------------------------------------------------
    Please remember to click "Mark as Answer" on the post that helps you, and to click "Unmark as Answer" if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.

    Friday, January 25, 2013 3:13 PM