Untitled

 avatar
unknown
plain_text
a year ago
3.8 kB
5
Indexable
Option Explicit

' Global declaration for the textBox for references
Dim textBoxReferences As MSForms.textBox
Dim selectedCategory As String
Dim selectedOptions As String
Dim eDocTypes As Variant

Private Sub TextBox1_Change()
    ' Automatically remove all spaces from the textBoxReferences
    textBoxReferences.Text = Replace(textBoxReferences.Text, " ", "")
End Sub

Private Sub UserForm_Initialize()
    Me.caption = "Send Email"
    Me.Width = 300
    Me.Height = 350
    
    ' Create Frame for job type selection
    Dim frameJobType As MSForms.Frame
    Set frameJobType = Me.Controls.Add("Forms.Frame.1", "frameJobType", True)
    With frameJobType
        .caption = "Select Job Type:"
        .left = 20
        .top = 20
        .Width = 100
        .Height = 80
    End With

    ' Create OptionButton for Bookings
    Dim optBookings As MSForms.OptionButton
    Set optBookings = frameJobType.Controls.Add("Forms.OptionButton.1", "optBookings", True)
    With optBookings
        .caption = "Bookings"
        .left = 40
        .top = 25
    End With

    ' Create OptionButton for Shipments
    Dim optShipments As MSForms.OptionButton
    Set optShipments = frameJobType.Controls.Add("Forms.OptionButton.1", "optShipments", True)
    With optShipments
        .caption = "Shipments"
        .left = 40
        .top = 10
    End With

    ' Create Frame for eDoc type selection
    Dim frameEdocType As MSForms.Frame
    Set frameEdocType = Me.Controls.Add("Forms.Frame.1", "frameEdocType", True)
    With frameEdocType
        .caption = "Select eDoc Type:"
        .left = 20
        .top = 120
        .Width = 100
        .Height = 140
    End With

    ' Define eDoc types in an array
    eDocTypes = Array("BKC", "BKG", "CIV", "EMA", "PAL", "PKL", "SWB", "HBL")

    ' Create OptionButtons for each eDoc type from the array
    Dim i As Integer
    Dim topPosition As Integer
    topPosition = 10
    For i = LBound(eDocTypes) To UBound(eDocTypes)
        Dim optButton As MSForms.OptionButton
        Set optButton = frameEdocType.Controls.Add("Forms.OptionButton.1", "opt" & eDocTypes(i), True)
        With optButton
            .caption = eDocTypes(i)
            .left = 40
            .top = topPosition
        End With
        topPosition = topPosition + 15
    Next i

    ' Initialize and create the textBoxReferences
    Set textBoxReferences = Me.Controls.Add("Forms.TextBox.1", "textBoxReferences", True)
    With textBoxReferences
        .MultiLine = True
        .WordWrap = True
        .EnterKeyBehavior = True
        .Scrollbars = fmScrollBarsBoth
        .top = 20
        .left = 150
        .Width = 100
        .Height = 200
    End With
End Sub

Private Sub Send_Click()
    Dim selectedCategory As String
    Dim selectedOptions As String
    Dim references As String
    Dim ctrl As Control

    ' Loop through controls to find the selected category and eDoc type
    For Each ctrl In Me.Controls
        If TypeName(ctrl) = "OptionButton" Then
            If ctrl.name = "optBookings" And ctrl.Value = True Then
                selectedCategory = "BKG"
            ElseIf ctrl.name = "optShipments" And ctrl.Value = True Then
                selectedCategory = "SHP"
            End If

            If ctrl.Value = True Then
                selectedOptions = ctrl.caption
            End If
        End If
    Next ctrl

    references = textBoxReferences.Text

    ' Call the ProcessReferences subroutine in Module1
    ProcessReferences selectedCategory, selectedOptions, references
    ' Unload the UserForm to close it
    Unload Me
End Sub

Private Sub Cancel_Click()
    Unload Me
End Sub
Editor is loading...
Leave a Comment