PSLine2000Documentation/Forms/Material Selection Screen.md

6.1 KiB

Material Selection Screen

Analysis generated on: 4/1/2025 4:04:59 PM

Record Source

  • None

Controls

Control Name Reference
Material (Row Source) Tables/[metalQ1];
CutTypes (Row Source)

VBA Code

Option Compare Database   'Use database order for string comparisons

Private Sub Button2_Click()
   Call ckPrimaryScreen
   ErrM.Caption = ""
   A = SelectBy
   b = SelWarehouse
   Select Case b
      Case 1
         Sw$ = ""
         sw2$ = ""
      Case 2
         Sw$ = " and Warehouse='90'"
         sw2$ = "Warehouse='90'"
      Case 3
         Sw$ = " and Warehouse='02'"
         sw2$ = "Warehouse='02'"
      Case Else
   End Select
   Select Case A
      Case 1
         Mater$ = itsaNull$(Material)
         If Mater$ <> "" Then
            DoCmd.OpenForm PrimaryScreen$, , , "MetalType='" + Mater$ + "'" + Sw$
         Else
            ErrM.Caption = "Invalid Material Selected"
         End If
      Case 2
         Mater$ = itsaNull$(Programmer)
         If Mater$ <> "" Then
            DoCmd.OpenForm PrimaryScreen$, , , "Programmer='" + Mater$ + "'" + Sw$
         Else
            ErrM.Caption = "Invalid Programmer Selected"
         End If
      Case 3
         Mater$ = itsaNull$(CutTypes)
         If Mater$ <> "" Then
            DoCmd.OpenForm PrimaryScreen$, , , "CutType='" + Mater$ + "'" + Sw$
         Else
            ErrM.Caption = "Invalid Cut Type Selected"
         End If
      Case 4
         DoCmd.OpenForm PrimaryScreen$, , , sw2$
      Case Else
   End Select

End Sub

Private Sub Button6_Click()
   ErrM.Caption = ""
   A = SelectBy
   Select Case A
      Case 1
         Mater$ = itsaNull$(Material)
         If Mater$ <> "" Then
            DoCmd.OpenReport "RSelectMaterial", A_PREVIEW, , "MetalType=" + Chr$(34) + Mater$ + Chr$(34)
         Else
            ErrM.Caption = "Invalid Material Selected"
         End If
      Case 2
         Mater$ = itsaNull$(Programmer)
         If Mater$ <> "" Then
            DoCmd.OpenReport "RSelectMaterial", A_PREVIEW, , "Programmer=" + Chr$(34) + Mater$ + Chr$(34)
         Else
            ErrM.Caption = "Invalid Programmer Selected"
         End If
      Case 3
         Mater$ = itsaNull$(CutTypes)
         If Mater$ <> "" Then
            DoCmd.OpenReport "RSelectMaterial", A_PREVIEW, , "Cuttype=" + Chr$(34) + Mater$ + Chr$(34)
         Else
            ErrM.Caption = "Invalid Cut Type Selected"
         End If
      Case 4
         DoCmd.OpenReport "RSelectMaterial", A_PREVIEW
      Case Else
   End Select
End Sub

Private Sub Button9_Click()
   ErrM.Caption = ""
   A = SelectBy
   Select Case A
      Case 1
         Mater$ = itsaNull$(Material)
         If Mater$ <> "" Then
            Call ckPrimaryScreen
            DoCmd.OpenForm PrimaryScreen$, A_FORMDS, , "MetalType=" + Chr$(34) + Mater$ + Chr$(34)
         Else
            ErrM.Caption = "Invalid Material Selected"
         End If
      Case 2
         Mater$ = itsaNull$(Programmer)
         If Mater$ <> "" Then
            Call ckPrimaryScreen
            DoCmd.OpenForm PrimaryScreen$, A_FORMDS, , "Programmer=" + Chr$(34) + Mater$ + Chr$(34)
         Else
            ErrM.Caption = "Invalid Programmer Selected"
         End If
      Case 3
         Mater$ = itsaNull$(CutTypes)
         If Mater$ <> "" Then
            Call ckPrimaryScreen
            DoCmd.OpenForm PrimaryScreen$, A_FORMDS, , "Cuttype=" + Chr$(34) + Mater$ + Chr$(34)
         Else
            ErrM.Caption = "Invalid Cut Type Selected"
         End If
      Case 4
         Call ckPrimaryScreen
         DoCmd.OpenForm PrimaryScreen$, A_FORMDS
      Case Else
   End Select

End Sub

Private Sub Command51_Click()
   Dim ProcDB As Database, ProcSet As Recordset
   Set ProcDB = DBEngine.Workspaces(0).Databases(0)
   Set ProcSet = ProcDB.OpenRecordset("Universal", DB_OPEN_DYNASET)  ' Create dynaset.

End Sub

Private Sub CutTypes_GotFocus()
   SelectBy = 3

End Sub

Private Sub Form_Load()
   SelectBy = 1
End Sub

Private Sub Material_GotFocus()
   SelectBy = 1

End Sub

Private Sub Programmer_GotFocus()
   SelectBy = 2

End Sub

What it does

Form Toggles and Report Openers

Overview

This VBA code is used to toggle between different forms in an Access application, as well as open reports. The form toggles are controlled by buttons with unique IDs (Button2, Button6, Button9), while the report opener is controlled by a command button (Command51).

Form Toggles

The following subroutines control the form toggles:

  • Button2_Click(): Opens a form (PrimaryScreen) based on the selected materials (Material or Programmer). The material type and warehouse are used to filter the results.
    • If no material is selected, an error message is displayed.
    • Otherwise, the form is opened with the specified parameters.
  • Button6_Click(): Opens a report (RSelectMaterial) based on the selected materials (Material or Programmer).
    • The report is opened in preview mode and filtered by the selected material type.
    • If no material is selected, an error message is displayed.
  • Button9_Click(): Opens a form (PrimaryScreen) based on the selected materials (Material or Programmer). This subroutine is similar to Button2_Click but uses a different parameter set.

Report Opener

The following subroutine opens a report:

  • Command51_Click(): Opens a report (RSelectMaterial) in preview mode. The report is filtered by the universal dataset.

Focus Events

The following focus events are used to change the form toggle settings:

  • CutTypes_GotFocus(): Sets the form toggle to 3 when the CutTypes control gains focus.
  • Form_Load() and Material_GotFocus(): Set the initial form toggle to 1 (for PrimaryScreen) when the application loads or the Material control gains focus.

Database Comparison

The following line sets the database comparison order for string comparisons:

Option Compare Database   'Use database order for string comparisons

This option ensures that string comparisons are performed in a case-sensitive manner, as specified by the Database comparison type.