Userform "X" close button not working second round

Raptor6L

New Member
Joined
Jan 18, 2018
Messages
8
Hi all

Ok, I got this working with the close button now closing the form the second time and beyond. Good job eduzs!

However, I'm stuck with referring to the userform from outside of the userform. I used to be able to refer back to it using the userform's name, however it seems that link is now broken. Something to do with the
Code:
Set MyForm = New Userform2
i'm guessing.

I've tried MyForm but that's not much chop either.

Train of code:

DATA_DUMP_PAGE UserForm
Code:
Private Sub DELETE_BUTTON_Click()

Application.ScreenUpdating = False


Dim MyForm As ADD_DEL_MAT_SHEET
Me.Hide
Set MyForm = New ADD_DEL_MAT_SHEET
MyForm.Show
Set MyForm = Nothing


End Sub
ADD_DEL_MAT_SHEET UserForm
Code:
Private Sub Delete_Material_Button_Click()

Application.ScreenUpdating = False


TRANSACTION_TEXT_BOX.Visible = True
Add_Material_Button.Visible = False
Delete_Single_Material_Questions


End Sub
Delete-Single_Material-Question()
Code:
Sub Delete_Single_Material_Questions()    
        Answer = MsgBox("YOU ARE ABOUT TO DELETE A MATERIAL LINE. ARE YOU SURE?", vbYesNo + vbQuestion + vbMsgBoxSetForeground, "TIME TO TAKE OUT THE TRASH?")
        
        If Answer = vbYes Then
            
            ADD_DEL_MAT_SHEET.TRANSACTION_TEXT_BOX.Visible = False
            ADD_DEL_MAT_SHEET.PHOTO_BLANK_TEXT.Visible = False
            ADD_DEL_MAT_SHEET.PHOTO_BLANK.Visible = False
            Application.ScreenUpdating = True
When the ADD_DEL_MAT_SHEET userform initially displays it has these three things set as Visible = True - and they are. Run the macros thru to what you see here and nothing changes, however the macro continues on, it doesn't error out there.

Eventually it does error out when it comes to:
Code:
ADD_DEL_MAT_SHEET.Hide
It gives error:
Run-time error '402':
Must close or hide topmost modal first
Any ideas anyone?

Cheers
Chris
 
Last edited:

Some videos you may like

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).

Raptor6L

New Member
Joined
Jan 18, 2018
Messages
8
Ok, i figured it out.

To refer back to the userform you need to create a public sub that contains the instructions within the userform, and refer to that public sub name from outside of the userform to execute those instructions.

Hope that makes sense?

Cheers
Chris
 

Watch MrExcel Video

Forum statistics

Threads
1,102,773
Messages
5,488,768
Members
407,657
Latest member
Sassy5

This Week's Hot Topics

  • Timer in VBA - Stop, Start, Pause and Reset
    [CODE=vba][/CODE] Option Explicit Dim CmdStop As Boolean Dim Paused As Boolean Dim Start Dim TimerValue As Date Dim pausedTime As Date Sub...
  • how to updates multiple rows in muliselect listbox
    Hello everyone. I need help with below code. code is only chaning 1st row in mulitiselect list box. i know issue with code...
  • Delete Row from Table
    I am trying to delete a row from a table using VBA using a named range to find what I need to delete. My Range is finding the right cell. In the...
  • Assigning to a variable
    I have a for each block where I want to assign the value in column 5 of the found row to the variable Serv. [CODE=vba] For Each ws In...
  • Way to verify information
    Hi All, I don't know what to call this formula, and therefore can't search. I have a spreadsheet with information I want to reference...
  • Active Cell Address – Inactive Sheet
    How to use VBA to get the cell address of the active cell in an inactive worksheet and then place that cell address in a location on the current...
Top