+ Reply to Thread
Results 1 to 5 of 5

My user form is not "Unloading" What Do I need to fix in my code?

  1. #1
    Registered User
    Join Date
    01-24-2024
    Location
    Trussville
    MS-Off Ver
    2010
    Posts
    12

    My user form is not "Unloading" What Do I need to fix in my code?

    I am trying to call up or initialize a user form from a worksheet that has a Yes, No drop down list in cell B7. If the user selects yes in B7, I want it to pull up this user form Wall_Collar_Location. I copied the code from somewhere and it seemingly works the way I want it, but, I can not figure out the unload part. The user form has 2 option buttons and one text box. I have tried using "Unload Me" in both the command button click code and just in the sheet code "Sheet 2" as well but the user form stays open unless you hard close it with the x button. I currently use this code in my worksheet to pull up the form but what do I need to change to unload it after I click the command button?

    Dim ltr As String
    Dim UForm As Object
    Dim i As Integer
    i = 0


    ltr = Sheet2.Range("B7").Value


    For Each UForm In VBA.UserForms
    UForm.Hide
    Unload VBA.UserForms(i)
    i = i + 1
    Next


    Select Case ltr
    Case "Yes"
    Wall_Collar_Location.Show

    End Select



    End Sub

  2. #2
    Registered User
    Join Date
    01-24-2024
    Location
    Trussville
    MS-Off Ver
    2010
    Posts
    12

    Re: My user form is not "Unloading" What Do I need to fix in my code?

    The code in my user form is as follows and it works as intended, It just does not close when I click the Command Button 1:
    I have tried putting unload me on the 3rd line down below Range("8B").Value = TextBox1.Value, but when you click the command button, the user form just blinks and stays open so I took it back out.

    Private Sub CommandButton1_Click()
    Range("B8").Value = TextBox1.Value

    End Sub


    Private Sub OptionButton1_Click()
    TextBox1.Enabled = True



    End Sub

    Private Sub OptionButton2_Click()
    TextBox1.Enabled = True



    End Sub
    Last edited by davidgeorge212; 01-30-2024 at 10:47 PM.

  3. #3
    Forum Expert
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    O365 32bit (Windows)
    Posts
    2,047

    Re: My user form is not "Unloading" What Do I need to fix in my code?

    Is the code in post #1 in a change event? If so, when you populate B8 with the command button it could be triggering that event and re-showing the form.

  4. #4
    Registered User
    Join Date
    01-24-2024
    Location
    Trussville
    MS-Off Ver
    2010
    Posts
    12
    Quote Originally Posted by ByteMarks View Post
    Is the code in post #1 in a change event? If so, when you populate B8 with the command button it could be triggering that event and re-showing the form.
    This very well could be my case. It is in a change event, is there another type of event that i can use here that might work better? Ideally i would like the user form to open uppon selecting an answer from a drop down list. I guess if need be, i could use a command button and open it the more traditional way

  5. #5
    Forum Expert
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    O365 32bit (Windows)
    Posts
    2,047

    Re: My user form is not "Unloading" What Do I need to fix in my code?

    You could try using Application.EnableEvents = False to turn off the events before populating B8. Just be sure to enable it again after.

+ 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. login with "A" user means in List box its should show only "A" user data"
    By krishnaji.B in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-22-2021, 07:28 AM
  2. Replies: 1
    Last Post: 02-22-2021, 07:12 AM
  3. login with "A" user means in List box its should show only "A" user data"
    By krishnaji.B in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-19-2021, 06:01 AM
  4. Replies: 0
    Last Post: 02-19-2021, 05:12 AM
  5. VBA Code to trim form rw "O" and make filename as rw "A"
    By asoekha in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-17-2021, 11:10 AM
  6. Request - "write vba code on buttons to make attached user form complete"
    By virgome in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-19-2013, 02:12 PM
  7. Adding "All Borders" with a User Form (Similar to Data Form)
    By kgreave1 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-26-2012, 01:57 PM

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