View Single Post
 
Old 02-10-2017, 12:24 PM
BlackGirlMagic's Avatar
BlackGirlMagic BlackGirlMagic is offline Windows 7 64bit Office 2010 64bit
Novice
 
Join Date: Feb 2017
Location: Washington, DC
Posts: 3
BlackGirlMagic is on a distinguished road
Red face Follow up question now using ListBox

This is what I've got so far. How can I save all of the variables (i.e. EmpName, EmpNum, ManagerName, etc) and when the new document opens up store those values into assigned textboxes?

Code:
Option Explicit

Private Sub UserForm_Initialize()
    EmpNameList.MultiSelect = 2       
    With EmpNameList
        .AddItem "Ally"
        .AddItem "Linda"
        .AddItem "Cameron"
        .AddItem "Ron"
        .AddItem "Tony"
    End With
    
End Sub

Private Sub EmpNameList_Change()
Select Case EmpName
 Case "Ally"
    With EmpNum
    EmpNum.Text = "1234"
    End With
    
    With ManagerName
    ManagerName.Text = "Jerry"
    End With
    
 Case "Linda"
    With EmpNum
    EmpNum.Text = "4567"
    End With

    With ManagerName
    ManagerName.Text = "Mike"
    End With

 Case "Cameron"
    With EmpNum
    EmpNum.Text = "6789"
    End With

    With ManagerName
    ManagerName.Text = "Tom"
    End With

 Case "Ron"
    With EmpNum
    EmpNum.Text = "0132"
    End With

    With ManagerName
    ManagerName.Text = "Ralph"
    End With

 Case "Tony"
    With EmpNum
    EmpNum.Text = "6783"
    End With

    With ManagerName
    ManagerName.Text = "Tom"
    End With
 End Select
End Sub

Private Sub cmdOK_Click()
    Dim fileName As String
    Dim Cost_Center
    Dim Auth_Date1
    Dim Auth_Date2
    Dim Emp_Name
    Dim Emp_Num
    Dim Man_Name
    EmpName.List = Array("Ally, Linda, Cameron, Ron, Tony")
    
'   Checking for completion of the form
    If CostCenter.Value = "" Then
        MsgBox "Please enter the Cost Center.", vbExclamation, "Input Data"
        CostCenter.SetFocus
        Exit Sub
    End If
    
    If AuthDate1.Value = "" Then
        MsgBox "Please enter the Period of Authorization.", vbExclamation, "Input Data"
        AuthDate1.SetFocus
        Exit Sub
    End If
    
    If AuthDate2.Value = "" Then
        MsgBox "Please enter the Period of Authorization.", vbExclamation, "Input Data"
        AuthDate2.SetFocus
        Exit Sub
    End If
    
    If EmpName.Value = "" Then
        MsgBox "Please select the Employee Name(s).", vbExclamation, "Input Data"
        EmpName.SetFocus
        Exit Sub
    End If
    
    If EmpNum.Value = "" Then
        MsgBox "Please enter the Employee Number(s).", vbExclamation, "Input Data"
        EmpNum.SetFocus
        Exit Sub
    End If
    
    If ManagerName.Value = "" Then
        MsgBox "Please enter the Authorizing Manager's Name.", vbExclamation, "Input Data"
        ManagerName.SetFocus
        Exit Sub
    End If

    Me.Hide

    Cost_Center = CostCenter.Value
    Auth_Date1 = AuthDate1.Value
    Auth_Date2 = AuthDate2.Value
    Emp_Name = EmpName.Value
    Emp_Num = EmpNum.Value
    Man_Name = ManagerName.Value

'   Creates new document to save as the Employee's Authorization Form
    fileName = EmpName.Value & "_LaborAuthorizationForm"
    Documents.Add "LaborAuthorizationForm.docm"
    With Dialogs(wdDialogFileSaveAs)
        .Name = fileName
        .Show
    End With

End Sub

Private Sub cmdCancel_Click()
    Me.Hide
End Sub
Reply With Quote