PSLine2000Documentation/Forms/Sheet Utilization Utilites.md

5.0 KiB

Sheet Utilization Utilites

Analysis generated on: 4/1/2025 4:02:30 PM

Record Source

  • None

Controls

Control Name Reference
None -

VBA Code

Option Compare Database
Option Explicit

Private Sub Command16_Click()
On Error GoTo Err_Command16_Click
    Dim frm As Form
    Dim stDocName As String
    Dim stLinkCriteria As String

    Call ckPrimaryScreen
    stDocName = PrimaryScreen$
    DoCmd.OpenForm stDocName
    For Each frm In Forms
       If frm.name = stDocName Then
          Exit For
       End If
    Next
    frm.recordSource = "Processes by List"
Exit_Command16_Click:
    Exit Sub

Err_Command16_Click:
    MsgBox Err.Description
    Resume Exit_Command16_Click
    

End Sub

Private Sub Sheet_Utilization_Click()
On Error GoTo Err_Sheet_Utilization_Click

    Dim stDocName As String
    Dim stLinkCriteria As String

    stDocName = "Utilization on Multiple Sheets"
    DoCmd.OpenForm stDocName, , , stLinkCriteria
    DoCmd.Close acForm, "Sheet Utilization Utilites"
Exit_Sheet_Utilization_Click:
    Exit Sub

Err_Sheet_Utilization_Click:
    MsgBox Err.Description
    Resume Exit_Sheet_Utilization_Click
    
End Sub

Private Sub Sort_by_Machine_Click()
On Error GoTo Err_Sort_by_Machine_Click

    Dim stDocName As String
    Dim stLinkCriteria As String

    stDocName = "Sorted by Machine"
    DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_Sort_by_Machine_Click:
    Exit Sub

Err_Sort_by_Machine_Click:
    MsgBox Err.Description
    Resume Exit_Sort_by_Machine_Click
    
End Sub
Private Sub Open_Form_Click()
On Error GoTo Err_Open_Form_Click

    Dim stDocName As String
    Dim stLinkCriteria As String

    stDocName = "Filtered Parts"
    DoCmd.OpenForm stDocName, , , stLinkCriteria
    DoCmd.Close acForm, "Sheet Utilization Utilites"

Exit_Open_Form_Click:
    Exit Sub

Err_Open_Form_Click:
    MsgBox Err.Description
    Resume Exit_Open_Form_Click
    
End Sub
Private Sub Sheet_Metal_Weight_Click()
On Error GoTo Err_Sheet_Metal_Weight_Click

    Dim stDocName As String
    Dim stLinkCriteria As String

    stDocName = "Sheet Metal Weight"
    DoCmd.OpenForm stDocName, , , stLinkCriteria
    DoCmd.Close acForm, "Sheet Utilization Utilites"

Exit_Sheet_Metal_Weight_Click:
    Exit Sub

Err_Sheet_Metal_Weight_Click:
    MsgBox Err.Description
    Resume Exit_Sheet_Metal_Weight_Click
    
End Sub

What it does

VBA Code Description

This VBA code is designed for a Microsoft Access application, specifically targeting the Form Controls feature. It provides event-driven macros that interact with various forms to perform specific tasks.

Overview

The code consists of five separate subroutines, each handling the click event of a button or command button in an Access form:

  1. Command16_Click
  2. Sheet_Utilization_Click
  3. Sort_by_Machine_Click
  4. Open_Form_Click
  5. Sheet_Metal_Weight_Click

Each subroutine performs a distinct function when triggered by its respective button click.

Common Pattern

A common pattern is observed across all subroutines:

  1. The subroutine begins with an On Error GoTo Err_\u003cSubroutine_Name\u003e statement, which sets the error handling mechanism to resume execution from the specified label (Err_\u003cSubroutine_Name\u003e) in case of an error.
  2. It initializes variables: stDocName and stLinkCriteria, which hold the names of forms and link criteria used for data retrieval or filtering.
  3. The subroutine performs form-related operations:
    • Opens a specific form using DoCmd.OpenForm stDocName, , , stLinkCriteria.
    • Retrieves any existing instances of the specified form using For Each frm In Forms and checks if they match the stDocName.
    • Sets the record source of an instance to "Processes by List" or closes a specific form.
  4. If errors occur during execution, the subroutine displays an error message box with the description of the error using MsgBox Err.Description.

Subroutine-Specific Functions

Here's a brief description of each subroutine's function:

  1. Command16_Click:
    • Opens the "Primary Screen" form and ensures only one instance is active.
    • Sets the record source to "Processes by List".
  2. Sheet_Utilization_Click:
    • Opens the "Utilization on Multiple Sheets" form and closes an existing instance of "Sheet Utilization Utilities".
  3. Sort_by_Machine_Click:
    • Opens the "Sorted by Machine" form without specifying any link criteria.
  4. Open_Form_Click:
    • Opens the "Filtered Parts" form with a specified link criterion, which is currently commented out (stLinkCriteria).
  5. Sheet_Metal_Weight_Click:
    • Similar to Sort_by_Machine_Click, opens the "Sheet Metal Weight" form without specifying any link criteria.

Conclusion

In summary, this VBA code provides event-driven functionality for Access forms, allowing users to interact with various controls and perform specific tasks when buttons are clicked. The code follows a consistent pattern, handling errors gracefully while executing its respective functions.