msfz751

MEntryPoints

May 19th, 2014
269
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ' >>>>>>>>>>>   MEntryPoints        <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  2. ' Description:  This module contains all the routines called by the menus
  3. '               and shortcut keys. These should all be fairly short routines,
  4. '               if necessary calling more complex routines in other modules
  5. '
  6. ' Authors:      Rob Bovey, www.appspro.com
  7. '               Stephen Bullen, www.oaltd.co.uk
  8. '
  9. ' Chapter Change Overview
  10. ' Ch#   Comment
  11. ' --------------------------------------------------------------
  12. ' 05    Initial version
  13. '
  14. Option Explicit
  15.  
  16. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  17. ' Comments: This procedure saves a copy of the completed time
  18. '           entry workbook to the specified consolidation
  19. '           location on the network.
  20. '
  21. ' Arguments:    None
  22. '
  23. ' Date          Developer       Chap    Action
  24. ' --------------------------------------------------------------
  25. ' 06/01/08      Rob Bovey       Ch05    Initial version
  26. '
  27. Public Sub PostTimeEntriesToNetwork()
  28.  
  29.     Dim sSheetTab As String
  30.     Dim sWeekEndDate As String
  31.     Dim sEmployee As String
  32.     Dim sSaveName As String
  33.     Dim sSavePath As String
  34.     Dim wksSheet As Worksheet
  35.     Dim wkbBook As Workbook
  36.     Dim vFullName As Variant
  37.    
  38.     ' Don't do anything unless our time entry workbook is active
  39.    ' wkbBook will return a reference to it if it is.
  40.    If bIsTimeEntryBookActive(wkbBook) Then
  41.    
  42.         ' Make sure the TimeEntry worksheet does not have any
  43.        ' data entry errors.
  44.        sSheetTab = sSheetTabName(wkbBook, gsSHEET_TIME_ENTRY)
  45.         Set wksSheet = wkbBook.Worksheets(sSheetTab)
  46.         If wksSheet.Range(gsRNG_HAS_ERRORS).Value Then
  47.             MsgBox gsERR_DATA_ENTRY, vbCritical, gsAPP_NAME
  48.             Exit Sub
  49.         End If
  50.    
  51.         ' Create a unique name for the time entry workbook.
  52.        sWeekEndDate = Format$( _
  53.                 wksSheet.Range(gsRNG_WEEK_END_DATE).Value, _
  54.                 "YYYYMMDD")
  55.         sEmployee = wksSheet.Range(gsRNG_EMPLOYEE_NAME).Value
  56.         sSaveName = sWeekEndDate & " - " & sEmployee & ".xls"
  57.        
  58.         ' Check the registry to determine if we already have a
  59.        ' consolidation path specified. If so, save the time
  60.        ' entry workbook to that location. If not, prompt the
  61.        ' user to identify a consolidation location, save that
  62.        ' location to the registry and save the time entry
  63.        ' workbook to that location.
  64.        sSavePath = GetSetting(gsREG_APP, gsREG_SECTION, _
  65.                 gsREG_KEY, "")
  66.         If Len(sSavePath) = 0 Then
  67.             ' No path was stored in the registry. Prompt the
  68.            ' user for one.
  69.            vFullName = Application.GetOpenFilename( _
  70.                     Title:=gsCAPTION_SELECT_FOLDER)
  71.             If vFullName <> False Then
  72.                 ' NOTE: The InStrRev function was not available
  73.                ' in Excel 97.
  74.                sSavePath = Left$(vFullName, _
  75.                     InStrRev(vFullName, "\"))
  76.                 SaveSetting gsREG_APP, gsREG_SECTION, _
  77.                     gsREG_KEY, sSavePath
  78.             Else
  79.                 ' The user cancelled the dialog.
  80.                MsgBox gsMSG_POST_FAIL, vbCritical, gsAPP_NAME
  81.                 Exit Sub
  82.             End If
  83.         End If
  84.        
  85.         wkbBook.SaveCopyAs sSavePath & sSaveName
  86.         MsgBox gsMSG_POST_SUCCESS, vbInformation, gsAPP_NAME
  87.        
  88.     Else
  89.         MsgBox gsMSG_BOOK_NOT_ACTIVE, vbExclamation, gsAPP_NAME
  90.     End If
  91.    
  92. End Sub
  93.  
  94.  
  95. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  96. ' Comments: This procedure allows the user to insert additional
  97. '           blank data entry rows at the bottom of the data
  98. '           entry table on the TimeEntry worksheet.
  99. '
  100. ' Arguments:    None
  101. '
  102. ' Date          Developer       Chap    Action
  103. ' --------------------------------------------------------------
  104. ' 06/01/08      Rob Bovey       Ch05    Initial version
  105. '
  106. Public Sub AddMoreRows()
  107.  
  108.     Const lOFFSET_COLS As Long = 5
  109.     Const lINPUT_COLS As Long = 6
  110.  
  111.     Dim rngInsert As Range
  112.     Dim wkbBook As Workbook
  113.     Dim wksSheet As Worksheet
  114.    
  115.     ' Don't do anything unless our time entry workbook is active
  116.    If bIsTimeEntryBookActive(wkbBook) Then
  117.  
  118.         ' Get a reference to the TimeEntry worksheet and the
  119.        ' insert row range on it. All new rows will be inserted
  120.        ' above this range.
  121.        Set wksSheet = wkbBook.Worksheets(sSheetTabName( _
  122.                                 wkbBook, gsSHEET_TIME_ENTRY))
  123.         Set rngInsert = wksSheet.Range(gsRNG_INSERT_ROW)
  124.        
  125.         ' Add a new row to the time entry table.
  126.        wksSheet.Unprotect
  127.         wksSheet.ScrollArea = ""
  128.         rngInsert.EntireRow.Insert
  129.         rngInsert.Offset(-2, 0).EntireRow.Copy _
  130.             Destination:=rngInsert.Offset(-1, 0)
  131.         rngInsert.Offset(-1, lOFFSET_COLS) _
  132.             .Resize(1, lINPUT_COLS).ClearContents
  133.         wksSheet.ScrollArea = _
  134.             wksSheet.Range(gsRNG_SET_SCROLL_AREA).Address
  135.         wksSheet.Protect , True, True, True
  136.        
  137.     Else
  138.         MsgBox gsMSG_BOOK_NOT_ACTIVE, vbExclamation, gsAPP_NAME
  139.     End If
  140.    
  141. End Sub
  142.  
  143.  
  144. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  145. ' Comments: This procedure clears the data entry cells on the
  146. '           active worksheet so that the worksheet can easily
  147. '           be reused for a new time period.
  148. '
  149. ' Arguments:    None
  150. '
  151. ' Date          Developer       Chap    Action
  152. ' --------------------------------------------------------------
  153. ' 06/01/08      Rob Bovey       Ch05    Initial version
  154. '
  155. Public Sub ClearDataEntryAreas()
  156.  
  157.     Dim rngToClear As Range
  158.     Dim wkbBook As Workbook
  159.    
  160.     ' Don't do anything unless our time entry workbook is active
  161.    If bIsTimeEntryBookActive(wkbBook) Then
  162.    
  163.         ' Make sure the active worksheet has the rgnClearInputs
  164.        ' defined name.
  165.        On Error Resume Next
  166.             Set rngToClear = _
  167.                 wkbBook.ActiveSheet.Range("rgnClearInputs")
  168.         On Error GoTo 0
  169.        
  170.         ' If the worksheet is an input worksheet, clear the
  171.        ' contents of the input area.
  172.        If Not rngToClear Is Nothing Then
  173.             rngToClear.ClearContents
  174.         End If
  175.    
  176.     Else
  177.         MsgBox gsMSG_BOOK_NOT_ACTIVE, vbExclamation, gsAPP_NAME
  178.     End If
  179.    
  180. End Sub
  181.  
  182.  
  183. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  184. ' Comments: This procedure exits the PETRAS application.
  185. '
  186. ' Arguments:    None
  187. '
  188. ' Date          Developer       Chap    Action
  189. ' --------------------------------------------------------------
  190. ' 06/01/08      Rob Bovey       Ch05    Initial version
  191. '
  192. Public Sub ExitApplication()
  193.     ShutdownApplication
  194. End Sub
Advertisement
Add Comment
Please, Sign In to add comment