+ Reply to Thread
Results 1 to 9 of 9

Userform related Excel application crash

Hybrid View

  1. #1
    Registered User
    Join Date
    04-25-2011
    Location
    Memphis, TN
    MS-Off Ver
    Excel 2007
    Posts
    19

    Userform related Excel application crash

    I can't seem to figure out what is causing Excel to freak out over the sequence below:

    Subroutine initializes the userform:
    Sub CreatePOUserForm()
    uf_1_CreatePO.Show
    End Sub
    Userform code:
    Private Sub UserForm_Initialize()
    
    Dim ws As Worksheet
    Dim iRow As Long
    Dim rngSuppliers As Range
    Dim Cell As Range
    Dim UniqueSupp As Collection
    Dim Supp As Variant
    
        iRow = 2
        Set ws = ThisWorkbook.Sheets("Suppliers")
        Set rngSuppliers = ws.Range("A" & iRow, ws.Range("A" & iRow).End(xlDown))
        Set UniqueSupp = New Collection
    
        On Error Resume Next
            For Each Cell In rngSuppliers.Cells
                UniqueSupp.Add Cell.Value, CStr(Cell.Value)
            Next Cell
        On Error GoTo 0
    
        For Each Supp In UniqueSupp
            Controls.Item("ComboBox1").AddItem Supp
        Next Supp
    End Sub
    User selection is passed through to MakeOrderTbl(Supp as String) subroutine:
    Private Sub CommandButton1_Click()
    
    Dim Supp As String
    
    Supp = Me.Controls.Item("ComboBox1").Value
    Unload Me
    Call MakeOrderTbl(Supp)
    
    End Sub
    I have "Stop" lines throughout the MakeOrderTbl(Supp as String) sub because I'm still tinkering with it. After stepping through a few stops, if I reset/end the procedure in the middle of MakeOrderTbl and then try to save the file, Excel crashes. I'm assuming the problem has to do with the way I'm initializing the userform, because if I run the Private Sub Userform_Initialize routine straight from the VBE, it doesn't cause a crash.

    Any ideas how to fix this? I've been searching the internet for the last two days and have tried a code cleaner and have also tried AdLoki's suggestion found here: http://www.excelforum.com/excel-prog...een-saved.html

    I also tried initializing the userform with:
    Sub Maint_btn_CreatePO_Click()
        uf_1_CreatePO.Show
    End Sub
    Sheetname "Maint" and button name "btn_CreatePO". I later saw this referenced without the sheetname+underscore prefix and have tried that as well.

    Thanks for your thoughts.
    Last edited by acellis9; 04-02-2014 at 03:08 PM. Reason: clarify pass-through variable in MakeOrderTbl sub name

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Userform related Excel application crash

    Hello acellis9,

    When you receive errors in your code, you should at least post the error number. There are many different errors. Knowing which one is being thrown helps track down the problem.

    For best results, you should post your workbook. The will allow the code to be fully tested and debugged. Please include before and after examples of the data along with any notes.
    If your workbook contains sensitive information, please redact it before posting.

    How To Post Your Workbook
    1. At the bottom right of the Reply window, Click the button Go Advanced
    2. At the top of the Your Message Window, in the first row of icons, Click the Paperclip icon.
    3. Click the Add Files button at the top right in the dialog box. This displays the File Manager dialog.
    4. Click the Select Files button at the bottom middle of the dialog.
    5. In the new window Find the file you want to upload, select it, and Click Open.
    6. You will now be back in the File Manager dialog. Click the bottom Middle button Upload File.
    7. Wait until the file has completely uploaded before you exit the File Manager dialog.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Registered User
    Join Date
    04-25-2011
    Location
    Memphis, TN
    MS-Off Ver
    Excel 2007
    Posts
    19

    Re: Userform related Excel application crash

    My sample workbook is attached.

    To recreate what I've described:
    Click the "Create PO" button on the "Maint" sheet
    Choose a supplier from the form's combobox
    The code will enter debug mode due to my having inserted Stop points
    Press F5 to continue stepping through until you reach the 4th Stop
            Sheets("TempScratch").Range("O2").Copy
                Sheets("TempScratch").Range("O2", Range("O" & iRowLast)).PasteSpecial Paste:=xlPasteFormulas
        Application.Calculation = xlCalculationAutomatic
        DoEvents
    Stop
        Sheets("TempScratch").Activate
        Sheets("TempScratch").Range("A1").Select
        Sheets("TempScratch").Range("A1", "O" & iRow).Copy
        Sheets("TempScratch").Range("A1").PasteSpecial Paste:=xlPasteValues
    While at this Stop, click the stop button in VBE to reset the procedure
    Enter cell R2 of the "TempScratch" sheet
    Key a plus sign at the end of the formula in R2 and then try to use Esc to exit the cell without making the change
    At this point, Esc may not work and you may have to click on another cell to move away from R2 which now displays as text containing the plus sign that you tried not to enter
    If you now attempt to save the workbook, Excel will crash.
    Attached Files Attached Files
    Last edited by acellis9; 04-03-2014 at 10:27 PM. Reason: spelling

  4. #4
    Registered User
    Join Date
    04-25-2011
    Location
    Memphis, TN
    MS-Off Ver
    Excel 2007
    Posts
    19

    Re: Userform related Excel application crash

    Hi Leith,

    I do not receive any errors in the code. The "error" occurs after resetting/ending the code in the middle of the MakeOrderTbl(Supp as String) subroutine. At this point Excel looks OK, but if I interact with a spreadsheet or formula it behaves oddly, such as the Esc key not functioning (after entering a cell with F2). If I then attempt to save the workbook, Excel stops responding and crashes.

    If I run the MakeOrderTbl sub alone, with an actual declaration of the Supp variable (instead of passing it through from the UserForm), it performs as expected, without crashing.

    If I run the UserForm_Initialize private sub from within the VBE (clicking the play button), it displays the form with populated combobox. Upon user selection from the combobox and subsequent clicking of the form's CommandButton1, the Supp variable is defined, passed through to MakeOrderTbl(Supp as String) and everything functions fine.

    Only when the extra step of initializing/showing the Userform is added (via a Button (Form Control) assigned with the CreatePOUserForm subroutine) does Excel spaz out.

    The error information is as follows:
    Problem signature:
    Problem Event Name: APPCRASH
    Application Name: EXCEL.EXE
    Application Version: 15.0.4569.1504
    Application Timestamp: 52c5ed10
    Fault Module Name: EXCEL.EXE
    Fault Module Version: 15.0.4569.1504
    Fault Module Timestamp: 52c5ed10
    Exception Code: c0000005
    Exception Offset: 00789991
    OS Version: 6.1.7601.2.1.0.256.48
    Locale ID: 1033

    Additional information about the problem:
    LCID: 1033
    skulcid: 1033

    I have to remove some information from the workbook and then will upload it shortly.

  5. #5
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Userform related Excel application crash

    What is code for MakeOrderTbl?
    • Please remember to mark threads Solved with Thread Tools link at top of page.
    • Please use code tags when posting code: [code]Place your code here[/code]
    • Please read Forum Rules

  6. #6
    Registered User
    Join Date
    04-25-2011
    Location
    Memphis, TN
    MS-Off Ver
    Excel 2007
    Posts
    19

    Re: Userform related Excel application crash

    Anyone have any ideas?

  7. #7
    Registered User
    Join Date
    04-25-2011
    Location
    Memphis, TN
    MS-Off Ver
    Excel 2007
    Posts
    19

    Re: Userform related Excel application crash

    If no one has any ideas what is causing the error, are their any suggestions for a better method of using userform variables in separate subroutines? I haven't worked with userforms before so I'm sure there's a better way than passing arguments into called subroutines.

  8. #8
    Registered User
    Join Date
    04-25-2011
    Location
    Memphis, TN
    MS-Off Ver
    Excel 2007
    Posts
    19

    Re: Userform related Excel application crash

    After a little further thought, I believe the Excel crashing that resulted from my initial process may have been due to my order of operations...unloading the userform before calling the outside subroutine and passing the variable (illustrated in my first post but shown here as well):
    Private Sub CommandButton1_Click()
    
    Dim Supp As String
    
    Supp = Me.Controls.Item("ComboBox1").Value
    Unload Me
    Call MakeOrderTbl(Supp)
    
    End Sub
    I think that had I used Me.Hide instead of Unload Me, and then waited to unload the userform in the MakeOrderTbl(Supp as String) subroutine like I ended up doing, Excel wouldn't have gotten confused and later crashed. I suspect that even though the code would "work", in that it still functioned to call the sub and pass the argument, Excel wasn't able to actually follow the chain of events since the argument was being passed from something that didn't exist (the userform had already been unloaded). Just a theory though.

    I'll leave this thread open for a little while in case someone with a better understanding of all of this wants to chime in. It would be nice to get some input on what is considered the "right" or "best" way to work with user-selected userform variables in outside subroutines.

  9. #9
    Registered User
    Join Date
    04-25-2011
    Location
    Memphis, TN
    MS-Off Ver
    Excel 2007
    Posts
    19

    Re: Userform related Excel application crash

    For those with similar questions in the future, I got the process to work by changing the way I passed the Supp variable.

    Instead of using an outside subroutine to show/initialize the userform and then have the userform call another outside subroutine while passing Supp...

    A subroutine now shows the userform which declares the user selection as a public variable. The userform is then hidden and is not unloaded until Supp is assigned in the original subroutine. This seems to work and I haven't had any crashes.

    Variable declared as public in the userform code:
    Option Explicit
    Public Supp As String
    
    Private Sub CommandButton1_Click()
    
    Supp = Me.Controls.Item("ComboBox1").Value
    Me.Hide
    
    'Unload Me
    'Call MakeOrderTbl(Supp)
    
    End Sub
    Userform initialized, public userform variable assigned, and userform unloaded as follows:
    Sub MakeOrderTbl()
    
    Dim wb As Workbook
    Dim wsInv As Worksheet
    Dim iRow As Long
    Dim iRowLast As Long
    Dim RowNum As Long
    Dim Supp As String
    
        uf_1_CreatePO.Show
        If uf_1_CreatePO.Supp = "" Then
            Exit Sub
        Else
            Set wb = ThisWorkbook
            Set wsInv = wb.Sheets("InventoryList")
            
            Application.ScreenUpdating = False
            
                Supp = uf_1_CreatePO.Controls.Item("ComboBox1").Value
                Unload uf_1_CreatePO
                
                'Code continues

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Formula related Crash on Opening File
    By Nodak in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 07:05 AM
  2. [SOLVED] Formula related Crash on Opening File
    By Nodak in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 02:05 AM
  3. Failed userform loading and cause application crash
    By noiseash in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-25-2005, 11:05 AM
  4. Fixing a Macro-related Crash in Excel
    By Danimagus in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-06-2005, 02:05 PM
  5. [SOLVED] Application.Quit en Excel crash
    By Jos Vens in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-08-2005, 09:06 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1