PSLine2000Documentation/Forms/DS Pedestal.md

3.6 KiB

DS Pedestal


Record Source

Controls

Control Name Reference
PartNumber PartNumber (from Queries/DataSheetQ1)
Operation Operation (from Queries/DataSheetQ1)
Elem1A Elem1A (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)
Field441 Elem1V1 (from Queries/DataSheetQ1)
Field443 Elem2A (from Queries/DataSheetQ1)
Field450 Elem2V1 (from Queries/DataSheetQ1)
Field451 Elem2V2 (from Queries/DataSheetQ1)
Field456 Elem3V1 (from Queries/DataSheetQ1)
Field465 Elem3A (from Queries/DataSheetQ1)
Field466 Elem4A (from Queries/DataSheetQ1)
Field469 Elem5A (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 Pedestal"
    DoCmd.Close
Exit Sub
die:
   Resume HelpMe

End Sub

What it does

VBA Code Description

Overview

This VBA code is used to handle the Form_Load event in an Access database application. The code ensures that a form is loaded correctly and prevents any errors from occurring.

Key Functions

1. Error Handling and Comparison Order

The first line, Option Compare Database, specifies that string comparisons should be performed using database order (DB). This means that when comparing strings, the database will perform an exact match, rather than a case-insensitive or lexicographic comparison.

2. Preventing Empty Form Loads

In the Form_Load event, the code checks if the PartNumber field in the form is null (IsNull(Me![PartNumber])). If it is null, the code skips the rest of the subroutine and exits using the End statement.

This prevents the form from loading with a blank value in the PartNumber field, which could potentially cause errors or issues with the application's functionality.

3. Loading a Form

The next line, HelpMe: DoCmd.SelectObject A_FORM, "DS Pedestal", loads a specific form named "DS Pedestal". The DoCmd.SelectObject method is used to select and load an object in the database.

However, this line has a flaw. By using the same label (HelpMe) as the error handler (die: Resume HelpMe), it creates a loop where the code will jump back to the error handler if an error occurs. This means that the form will never be loaded correctly.

4. Closing and Exiting

The line DoCmd.Close closes the currently active form, but this is unnecessary since the form has already been loaded by the previous line.

Finally, the Exit Sub statement exits the subroutine without proceeding to any further code.

5. Error Handling and Looping

In the event of an error (die: Resume HelpMe), the code jumps back to the error handler using the same label as the main loop (HelpMe). This creates a loop where the code will continue to jump back and forth between the two labels, preventing any actual form loading.

Overall, this VBA code is poorly designed due to the looping issue caused by using the same label for both the main loop and the error handler.