+ Reply to Thread
Results 1 to 6 of 6

Variable accross form to module

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    02-24-2010
    Location
    Dublin, Ireland
    MS-Off Ver
    Excel 2003
    Posts
    195

    Thumbs down Variable accross form to module

    I have the below code, which is working perfactly for me.
    However, I want to move the 'Sub Event_Date' from the userform to the actual module.
    what ammendments do I need to consider rather than just doing a cut and paste on the code?
    Cheers guys

    
    '''''''''''''''''''''''''
    '''Send Event Report'''
    '''''''''''''''''''''''''
    Private Sub CommandButton9_Click()
    
    SendDirect = CheckBox3.Value
    
    Call Event_Date
    Call Assign_Event_Paths(EventMonth, EventYear)
    Call CheckFilesExistLending
    
    End Sub
    
    ''''''''''''''''''''''''
    '''Dates for Event''''
    ''''''''''''''''''''''''
    Sub Event_Date()
    
    If UserForm1.TextBox5.Value = "" Then
    MsgBox ("Enter Month For Report")
    NoRangeDate = True
    Exit Sub
    Else
    NoDate = False
    EventMonth = UserForm1.TextBox5.Value
    EventYear = UserForm1.TextBox6.Value
    End If
    
    If UserForm1.TextBox6.Value = "" Then
    MsgBox ("Enter Year For Report")
    NoRangeDate = True
    Exit Sub
    Else
    NoDate = False
    EventMonth = UserForm1.TextBox5.Value
    EventYear = UserForm1.TextBox6.Value
    End If
    
    End Sub

  2. #2
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,983

    Re: Variable accross form to module

    That doesn't appear to make any sense since the sub just checks if two textboxes are filled in. Why do you want to move it out of the form's code module?
    Everyone who confuses correlation and causation ends up dead.

  3. #3
    Forum Contributor
    Join Date
    02-24-2010
    Location
    Dublin, Ireland
    MS-Off Ver
    Excel 2003
    Posts
    195

    Re: Variable accross form to module

    I have the Assign Paths to Variable code with in the module, Ive included that below.
    I want to move all subs from the UserForm and leave it as a script of Call commands if at all possible.

    
    Sub Assign_Event_Paths(EventMonth As String, EventYear As String)
    
    Dim filepaths(100) As Variant
    EventPath = "\\vs1alpfc1\bkcPMU\MIS Reports\Event Report\Results\" & EventYear & "\" & EventMonth & ""
    
    EventBusiness = EventPath & "Bus Event Report " & Format(LendMonth, "mmm") & " " & EventYear & ".xls"
    EventPersonal = EventPath & "Personal Event Report " & Format(LendMonth, "mmm") & " " & EventYear & ".xls"
    
    End Sub

  4. #4
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,983

    Re: Variable accross form to module

    All I can see that achieving is creating a need for public variables (which is bad), unless you rewrite all your code. If you want to separate logic from interface (which is a good aim) your button click should call one routine and pass it all the variables required from the form. The called routine should then call the other routines passing local variables as required.

  5. #5
    Forum Contributor
    Join Date
    02-24-2010
    Location
    Dublin, Ireland
    MS-Off Ver
    Excel 2003
    Posts
    195

    Re: Variable accross form to module

    Cheers for the advice, I think I'll give it a shot!

  6. #6
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,983

    Re: Variable accross form to module

    For the record, I would keep the validation of the textboxes in the form's code:
    Private Sub CommandButton9_Click()
      If Me.TextBox5.Value = "" Then
        MsgBox "Enter Month For Report"
        exit sub
      End If
      If Me.TextBox6.Value = "" Then
        MsgBox "Enter Year For Report"
        Exit Sub
      End If
      RunCodeToDoLotsOfStuffHere
    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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