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:

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
 

Forum statistics

Threads
1,082,151
Messages
5,363,430
Members
400,736
Latest member
Aida

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top