Dansk Regneark Forum
  Hjælp Hjælp  Søg i forum   Arrangementer   Opret ny bruger Opret ny bruger  Log ind Log ind


Emne lukketHvordan får jeg en userform til at lukke efter bru

 Besvar Besvar
Forfatter
Mikedk64 Se dropdown
Forum Begynder
Forum Begynder


Medlem: 16.Jun.2017
Status: Offline
Point: 8
Direkte link til dette indlæg Emne: Hvordan får jeg en userform til at lukke efter bru
    Sendt: 12.Jul.2017 kl. 09:29
Hej,

Jeg har en userform hvor jeg har kodet den til at fortælle hvis jeg har glemt at udfylde nogen af felterne.

Jeg kunne virkelig godt tænke mig at have det sådan at når jeg har trykket "add" i min userform, altså når jeg har udfyldt det hele, så lukker userformen.

Jeg har prøvet at indsætte en "Unload me", men hvis jeg gør dette, så virker min kode til at fortælle hvis jeg mangler at udfylde noget ikke.

Hvordan pokker får jeg begge koder til at virke :)
Dette er min kode:

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
Til top



Til top
 Besvar Besvar

Skift forum Forum tilladelser Se dropdown

© 2010 - 2024 Dansk Regneark Forum - en del af Excel-regneark.dk