Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 07-12-2017, 12:16 AM
Mikedk64 Mikedk64 is offline Userform close after use Windows 10 Userform close after use Office 2010 64bit
Novice
Userform close after use
 
Join Date: Jul 2017
Posts: 4
Mikedk64 is on a distinguished road
Default Userform close after use

Hi,



I don't know if this is possible, but if anyone can answer, must it be you guys

I have this userform, where I have a code that tells you, if you forgot to fill out a box.
I would love to have it so the userform closes after you have pressed the Add button.

If i use a "unload me" in the vba, is there a Rune-time error 2110, because it cant make focus on the boxes you didnt fill out.
So in my eyes do I have the option to have the msgbox telling you miss a box OR that the userform closes after pressing the Add button.

Is there a way to make both work?
This is the code

Code:
Private Sub Label1_Click()
If Len(Label1.Caption) <> 0 Then
        Shell "explorer.exe" & " " & Label1.Caption, vbNormalFocus
    End If
    End Sub
Private Sub Add_Click()


If Theme.ListIndex = -1 Then
Cancel = 1
MsgBox ("Please Select Theme")
Theme.SetFocus
Exit Sub
End If


If Age.ListIndex = -1 Then
Cancel = 1
MsgBox ("Please Select Age")
Age.SetFocus
Exit Sub
End If


If Gender.ListIndex = -1 Then
Cancel = 1
MsgBox ("Please Select Gender")
Gender.SetFocus
Exit Sub
End If


If Resp.ListIndex = -1 Then
Cancel = 1
MsgBox ("Please Select Responsible")
Resp.SetFocus
Exit Sub
End If


If Month.ListIndex = -1 Then
Cancel = 1
MsgBox ("Please Select Month")
Month.SetFocus
Exit Sub
End If


If Year.ListIndex = -1 Then
Cancel = 1
MsgBox ("Please Select Year")
Year.SetFocus
Exit Sub
End If


If Label1 = "" Then
Cancel = 1
MsgBox ("Please Select Folder")
Exit Sub
End If


Dim erow As Long
Arow = Sheet1.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
Cells(Arow, 7).Value = Type1.Value
If Type1.Value <> "" Then
    Cells(Arow, 1).Value = Theme.Value
    Cells(Arow, 2).Value = Val(Age.Text)
    Cells(Arow, 3).Value = Gender.Value
    Cells(Arow, 4).Value = Resp.Text
    Cells(Arow, 5).Value = Month.Value
    Cells(Arow, 6).Value = Year.Value
    Cells(Arow, 8).Value = Label1.Caption
    ActiveSheet.Hyperlinks.Add Anchor:=Cells(Arow + 0, 8), Address:=Label1.Caption, TextToDisplay:=Label1.Caption
End If




Brow = Sheet1.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
Cells(Brow, 7).Value = Type2.Value
If Type2.Value <> "" Then
    Cells(Brow, 1).Value = Theme.Value
    Cells(Brow, 2).Value = Val(Age.Text)
    Cells(Brow, 3).Value = Gender.Value
    Cells(Brow, 4).Value = Resp.Text
    Cells(Brow, 5).Value = Month.Value
    Cells(Brow, 6).Value = Year.Value
    Cells(Brow, 8).Value = Label1.Caption
    ActiveSheet.Hyperlinks.Add Anchor:=Cells(Brow + 0, 8), Address:=Label1.Caption, TextToDisplay:=Label1.Caption
End If




Crow = Sheet1.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
Cells(Crow, 7).Value = Type3.Value
If Type3.Value <> "" Then
    Cells(Crow, 1).Value = Theme.Value
    Cells(Crow, 2).Value = Val(Age.Text)
    Cells(Crow, 3).Value = Gender.Value
    Cells(Crow, 4).Value = Resp.Text
    Cells(Crow, 5).Value = Month.Value
    Cells(Crow, 6).Value = Year.Value
    Cells(Crow, 8).Value = Label1.Caption
    ActiveSheet.Hyperlinks.Add Anchor:=Cells(Crow + 0, 8), Address:=Label1.Caption, TextToDisplay:=Label1.Caption
End If




Drow = Sheet1.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
Cells(Drow, 7).Value = Type4.Value
If Type4.Value <> "" Then
    Cells(Drow, 1).Value = Theme.Value
    Cells(Drow, 2).Value = Val(Age.Text)
    Cells(Drow, 3).Value = Gender.Value
    Cells(Drow, 4).Value = Resp.Text
    Cells(Drow, 5).Value = Month.Value
    Cells(Drow, 6).Value = Year.Value
    Cells(Drow, 8).Value = Label1.Caption
    ActiveSheet.Hyperlinks.Add Anchor:=Cells(Drow + 0, 8), Address:=Label1.Caption, TextToDisplay:=Label1.Caption
End If




erow = Sheet1.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
Cells(erow, 7).Value = Type5.Value
If Type5.Value <> "" Then
    Cells(erow, 1).Value = Theme.Value
    Cells(erow, 2).Value = Val(Age.Text)
    Cells(erow, 3).Value = Gender.Value
    Cells(erow, 4).Value = Resp.Text
    Cells(erow, 5).Value = Month.Value
    Cells(erow, 6).Value = Year.Value
    Cells(erow, 8).Value = Label1.Caption
    ActiveSheet.Hyperlinks.Add Anchor:=Cells(erow + 0, 8), Address:=Label1.Caption, TextToDisplay:=Label1.Caption
End If




Frow = Sheet1.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
Cells(Frow, 7).Value = Type6.Value
If Type6.Value <> "" Then
    Cells(Frow, 1).Value = Theme.Value
    Cells(Frow, 2).Value = Val(Age.Text)
    Cells(Frow, 3).Value = Gender.Value
    Cells(Frow, 4).Value = Resp.Text
    Cells(Frow, 5).Value = Month.Value
    Cells(Frow, 6).Value = Year.Value
    Cells(Frow, 8).Value = Label1.Caption
    ActiveSheet.Hyperlinks.Add Anchor:=Cells(Frow + 0, 8), Address:=Label1.Caption, TextToDisplay:=Label1.Caption
End If
End Sub


Private Sub Label9_Click()


End Sub


Private Sub Source_Click()
    Dim FolderPath As Object
   
    With Label1
        .BackStyle = fmBackStyleTransparent
        .Font.Name = "Courier New"
        .Font.Underline = True
        .Font.Bold = True
        .Font.Size = 10
        .WordWrap = False
        .ForeColor = vbBlue
        .ControlTipText = "Click Link to open folder."
        Set FolderPath = CreateObject("Shell.Application").BrowseForFolder(0, "Select a Folder...", 0, 0)
        If Not TypeName(FolderPath) = "Nothing" Then Label1.Caption = FolderPath.Items.Item.Path
    End With
    Set FolderPath = Nothing
End Sub


Private Sub Clear_Click()
Dim c As Control
    
    For Each c In Me.Controls
        Select Case TypeName(c)
            Case "TextBox", "ComboBox"
                c.Text = ""
        End Select
    Next c
End Sub

Private Sub UserForm_Initialize()
    Label1.Caption = ""
    Label1.BackStyle = fmBackStyleTransparent
End Sub
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Userform calls other userform, then populate worksheet Lehoi Excel Programming 0 02-03-2016 02:58 PM
Auto_open & Close gacartwright Excel Programming 0 07-29-2015 03:53 PM
VBA Code in a UserForm module to delete a Command Button which opens the userform Simoninparis Word VBA 2 09-21-2014 03:50 AM
Userform close after use Is it possible to take an input from a UserForm in one document to a UserForm in a do BoringDavid Word VBA 5 05-09-2014 09:08 AM
Userform close after use Close Printpreview and load a Userform Francisco Sousa Word VBA 7 07-07-2012 02:16 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 07:34 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft