UtterAccess HomeUtterAccess Wiki

Welcome Guest ( Log In | Register )

Custom Search
Edit Discussion
> SetTabCycle    
CODE

' Code courtesy of UtterAccess Wiki
' http://www.utteraccess.com/wiki/index.php/Category:FunctionLibrary
'
' You are free to use this code in any application,
' provided this notice is left unchanged.
'
' REV  DATE                          DESCRIPTION
' 1.0  2010-08-06              initial release
' 1.1  2010-09-12              revised function header
'
'==============================================================================
' NAME: SetTabCycle
' PURPOSE: Sets the Cycle property on a given form or all forms w/ exceptions
' RETURNS:  Boolean, status: False on error/unsuccessful
' ARGUMENTS:
'   lCycle: eTabCycle: Value to set the Cycle property to
'   Optional sExceptions: Semicolon delim list of form names to skip when
'                         processing all forms; not used if bSingleForm
'   Optional bSingleForm: Boolean, true to process only a single form
'   Optional bSingleFormName: required with bSingleForm, formname to process
'
' (include this enum in a module)
'Public Enum eTabCycles
'  dsTabCycleAllRecords = 0
'  dsTabCycleCurrentRecord = 1
'  dsTabCycleCurrentPage = 2
'End Enum
'==============================================================================
'ErrHandler V3.01

Public Function SetTabCycle( _
   Optional lCycle As eTabCycles = dsTabCycleCurrentRecord, _
   Optional sExceptions As String = ";", _
   Optional bSingleForm As Boolean = False, _
   Optional sSingleFormName As String = "" _
   ) As Boolean
On Error GoTo Error_Proc
Dim Ret As Boolean
'=========================
 Const cUTIL_OPEN As String = "UtilOpen" 'in case the form requires an openarg
 Dim sFormName As String
 Dim i As Integer 'loop iterations
 Dim iCount As Integer 'number of forms updated
 Dim vDummy As Variant 'formname verification variable
'=========================

 
 If bSingleForm Then
   'process single form
   
   'make sure it exists
   On Error Resume Next
   vDummy = CurrentProject.AllForms(sSingleFormName).Name
   Err.Clear
   On Error GoTo Error_Proc
   If IsNull(vDummy) Then
     MsgBox "Form not found!", vbCritical, "Not Found"
     GoTo Exit_Proc
   End If
   
   'make sure it's not open
   On Error Resume Next
   vDummy = Forms(sSingleFormName).Name
   Err.Clear
   On Error GoTo Error_Proc
   If Not IsNull(vDummy) Then
     MsgBox "Form is open, close it and try again", vbInformation, "Close Form"
     GoTo Exit_Proc
   End If
   
   'make the change
   DoCmd.OpenForm sSingleFormName, acDesign, , , , acHidden, cUTIL_OPEN
   Forms(sSingleFormName).Cycle = lCycle
   DoCmd.Close acForm, sSingleFormName, acSaveYes
 
 Else
   'process multiple forms
   sExceptions = ";" & sExceptions & ";"
 
   If Forms.Count <> 0 Then
     MsgBox "Close All Forms!"
     GoTo Exit_Proc
   End If
 
   iCount = 0
 
   For i = 0 To CurrentProject.AllForms.Count - 1
     sFormName = CurrentProject.AllForms(i).Name
     If InStr(1, sExceptions, ";" & sFormName & ";") = 0 Then
       DoCmd.OpenForm sFormName, acDesign, , , , acHidden, cUTIL_OPEN
       DoEvents
       If Forms(sFormName).Cycle <> lCycle Then
         Forms(sFormName).Cycle = lCycle
         DoCmd.Close acForm, sFormName, acSaveYes
         iCount = iCount + 1
       Else
         DoCmd.Close acForm, sFormName, acSaveNo
       End If
       DoEvents: DoEvents: DoEvents
     End If
   Next i
 
   MsgBox "SetTabCycle complete: " & iCount & " forms updated"

 End If


 Ret = True
'=========================
Exit_Proc:
 SetTabCycle = Ret
 Exit Function
Error_Proc:
 Select Case Err.Number
   Case Else
     MsgBox "Error: " & Trim(Str(Err.Number)) & vbCrLf & _
       "Desc: " & Err.Description & vbCrLf & vbCrLf & _
       "Procedure: SetTabCycle" _
       , vbCritical, "Error!"
 End Select
 Resume Exit_Proc
 Resume
End Function


Creative Commons License
SetTabCycle by UtterAccess Wiki is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Editing and revision of the content is freely encouraged; for details, see Expected Usage.

Edit Discussion
Custom Search
Thank you for your support!
This page has been accessed 4,007 times.  This page was last modified 09:02, 6 April 2011 by Jack Leach.   Disclaimers