PSLine2000Documentation/Forms/DS Laser.md

3.8 KiB

DS Laser


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)
Elem3V1 Elem3V1 (from Queries/DataSheetQ1)
Elem3V2 Elem3V2 (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)

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 Laser"
    DoCmd.Close
Exit Sub
die:
   Resume HelpMe
End Sub

What it does

Code Description

VBA Code Overview

This VBA code is written in an Access database and appears to be a form load event handler. It contains two primary sections: error handling and the main logic.

Error Handling Section

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

This section defines an error handling mechanism using the On Error statement, which redirects control to the labeled block of code (die) when an error occurs.

  • The first line, Option Compare Database, specifies that string comparisons in this module should be performed in database order.
  • The Private Sub Form_Load() statement defines the event handler for the form load event. This event is triggered when the form is loaded into memory after it has been opened from a database.
  • Inside the event handler, there's an error handling mechanism using On Error GoTo die. If any errors occur during the execution of this code, control will be transferred to the block labeled die.
  • The subsequent line checks if the PartNumber field on the form is null (IsNull(Me![PartNumber])). If it is null, the code attempts to exit the subroutine using the End statement.

Main Logic Section

HelpMe:
    DoCmd.SelectObject A_FORM, "DS Laser"
    DoCmd.Close
Exit Sub
die:
   Resume HelpMe

This section contains the main logic of the event handler:

  • The block labeled HelpMe contains two statements that interact with other forms in the database.
    • DoCmd.SelectObject A_FORM, "DS Laser" selects an object (in this case, a form named "DS Laser") using the DoCmd.SelectObject method. The parameter A_FORM is likely a constant or variable representing the current form's ID.
    • DoCmd.Close closes the selected form using the DoCmd.Close method.
  • The block labeled die: contains two statements that catch and handle errors when they occur:
    • Resume HelpMe: This statement transfers control back to the HelpMe block of code if an error occurs. This allows the code to recover from errors by re-executing the code in this section.

Conclusion

In summary, this VBA code handles form load events in an Access database. It checks for a null PartNumber field on the current form and attempts to close another form named "DS Laser" if necessary. The code includes robust error handling using the On Error GoTo die statement to ensure that it can recover from errors and resume execution as intended.