PSLine2000Documentation/Forms/DS Polish.md

4.6 KiB

DS Polish

Analysis generated on: 4/1/2025 4:10:56 PM

Record Source

Controls

Control Name Reference
PartNumber PartNumber (from Queries/DataSheetQ1)
Operation Operation (from Queries/DataSheetQ1)
Elem1A Elem1A (from Queries/DataSheetQ1)
Elem2A Elem2A (from Queries/DataSheetQ1)
Elem3A Elem3A (from Queries/DataSheetQ1)
Paperwork Paperwork (from Queries/DataSheetQ1)
TotalSelectTime TotalSelectTime (from Queries/DataSheetQ1)
StandardMinutes/part StandardMinutes/part (from Queries/DataSheetQ1)
pf&d pf&d (from Queries/DataSheetQ1)
StandardHours/part StandardHours/part (from Queries/DataSheetQ1)
StandardParts StandardParts (from Queries/DataSheetQ1)
Elem4A Elem4A (from Queries/DataSheetQ1)
Elem5A Elem5A (from Queries/DataSheetQ1)
Field97 Elem1V1 (from Queries/DataSheetQ1)
Field100 Elem2V1 (from Queries/DataSheetQ1)
Field105 Elem3V1 (from Queries/DataSheetQ1)
Field140 Elem6A (from Queries/DataSheetQ1)
Field144 Elem7A (from Queries/DataSheetQ1)
Field179 Elem8A (from Queries/DataSheetQ1)
Field235 Elem4V1 (from Queries/DataSheetQ1)
Field271 Elem8A (from Queries/DataSheetQ1)
Field272 Elem9A (from Queries/DataSheetQ1)
Field273 Elem5V1 (from Queries/DataSheetQ1)
Field274 Elem6V1 (from Queries/DataSheetQ1)
Field275 Elem7V1 (from Queries/DataSheetQ1)
Field276 Elem8V1 (from Queries/DataSheetQ1)
Field277 Elem9V1 (from Queries/DataSheetQ1)

VBA Code

Option Compare Database   'Use database order for string comparisons

Private Sub Form_Load()
   On Error GoTo die
   If IsNull(Me![PartNumber]) Then
      End
   End If
Exit Sub
HelpMe:
    DoCmd.SelectObject A_FORM, "DS CNC"
    DoCmd.Close
Exit Sub
die:
   Resume HelpMe

End Sub

What it does

VBA Code Description

Overview

This VBA code is a subroutine attached to the Form_Load event in Access. It is designed to handle the loading of a form when the application loads.

Code Breakdown

Option Compare Database

The first line, Option Compare Database, specifies that string comparisons should be done using the database's collation order (also known as locale-specific sorting). This ensures that strings are sorted according to the specific character set and cultural settings used in the database.

Private Sub Form_Load()

This is the name of the subroutine that will be executed when the form is loaded. The Private access modifier means that this subroutine can only be accessed within the current module.

On Error GoTo die

The On Error GoTo statement sets up an error-handling mechanism. If an error occurs in the code, it will transfer control to the label "die".

If IsNull(Me![PartNumber]) Then End

This line checks if the value of the PartNumber field on the current form is null (IsNull returns True for a null value). If so, the subroutine ends.

HelpMe:

DoCmd.SelectObject A_FORM, "DS CNC"
DoCmd.Close
Exit Sub

This section of code is skipped if an error occurs in the previous line. It performs two actions:

  • DoCmd.SelectObject A_FORM, "DS CNC": Selects a new form object with the name "DS CNC" and assigns it to the current form.
  • DoCmd.Close: Closes the currently open document (which is now replaced by the newly selected form).
  • Exit Sub: Exits the subroutine.

die:

This label marks the point where execution will resume if an error occurs in the previous line. The code after this label (Resume HelpMe) transfers control back to the "HelpMe:" section of the code, allowing it to continue executing normally.

Purpose and Usage

In summary, this VBA code is designed to load a specific form ("DS CNC") when the application loads. It checks if the PartNumber field on the current form is null before proceeding. If an error occurs during this check, it will transfer control to the "HelpMe:" section of the code and attempt to load the new form.

Best Practices

This code follows standard VBA best practices:

  • Uses meaningful variable names (A_FORM instead of a hardcoded value)
  • Includes descriptive comments (although they are not necessary in this simple case)
  • Handles errors using On Error GoTo
  • Uses Private access modifiers to restrict subroutine access

However, consider adding more error-handling code or logging mechanisms to make the application more robust and reliable.