# Material Upgrade old Analysis generated on: 4/1/2025 4:09:00 PM --- ## Record Source - [[Queries/Processes by material]] ## Controls | Control Name | Reference | |--------------|-----------| | *None* | - | ## VBA Code ```vba Option Compare Database Private Sub Command13_Click() Dim MainDB As Database, MainSet As Recordset Dim MainDB2 As Database, MainSet2 As Recordset Set MainDB = DBEngine.Workspaces(0).Databases(0) Set MainDB2 = DBEngine.Workspaces(0).Databases(0) lblstatus.Caption = "Setting up Database" Dim stDocName As String Command16.Enabled = False stDocName = "Processes by material 2" DoCmd.OpenQuery stDocName, acNormal, acEdit lblstatus.Caption = "Moving Parts to AS400" Set MainSet = MainDB.OpenRecordset("RMSFILES#_IEMUP1A0") ' Create dynaset. Set MainSet2 = MainDB2.OpenRecordset("Process by material") ' Create dynaset. lblstatus.Caption = "Purging AS400 product number file" On Error Resume Next MainSet.MoveFirst On Error GoTo 0 Do If Not (MainSet.EOF) Then MainSet.Delete DoEvents Else DoEvents Exit Do End If MainSet.MoveNext Loop '"Purging AS400 result file" MainSet2.MoveFirst Do If Not (MainSet2.EOF) Then p$ = MainSet2!prt MainSet.AddNew MainSet!PRDNO = p$ MainSet.Update DoEvents Else DoEvents Exit Do End If MainSet2.MoveNext Loop lblstatus.Caption = "Activating AS400 Program" DoEvents ActiveXCtl24.DoClick stDocName = "Processes by material 2d" DoCmd.OpenQuery stDocName, acNormal, acEdit lblstatus.Caption = "Done" DoCmd.OpenTable "Process by material 2" Exit_Command13_Click: Command16.Enabled = True Exit Sub Err_Command13_Click: MsgBox Err.Description Resume Exit_Command13_Click End Sub Private Sub Command16_Click() On Error GoTo Err_Command16_Click Dim stDocName As String Dim stLinkCriteria As String stDocName = "14" + Chr$(34) + " Process Sheet" DoCmd.OpenForm stDocName Forms![14" Process Sheet].recordSource = "Processes by material 4" DoCmd.Close acForm, "Material Upgrade" Exit_Command16_Click: Exit Sub Err_Command16_Click: MsgBox Err.Description Resume Exit_Command16_Click End Sub Private Sub Command2_Click() On Error GoTo Err_Command2_Click Dim stDocName As String Command3.Enabled = False stDocName = "Processes by material 2" DoCmd.OpenQuery stDocName, acNormal, acEdit Call Command4_Click stDocName = "Processes by material 2a" DoCmd.OpenQuery stDocName, acNormal, acEdit DoCmd.OpenTable "Process by material" Exit_Command2_Click: Command3.Enabled = True Exit Sub Err_Command2_Click: MsgBox Err.Description Resume Exit_Command2_Click End Sub Private Sub Command3_Click() On Error GoTo Err_Command3_Click Dim stDocName As String Dim stLinkCriteria As String stDocName = "14" + Chr$(34) + " Process Sheet" DoCmd.OpenForm stDocName Forms![14" Process Sheet].recordSource = "Processes by material 3" DoCmd.Close acForm, "Material Upgrade" Exit_Command3_Click: Exit Sub Err_Command3_Click: MsgBox Err.Description Resume Exit_Command3_Click End Sub Private Sub Command4_Click() Dim MainDB As Database, MainSet As Recordset Dim MainDB2 As Database, MainSet2 As Recordset Set MainDB = DBEngine.Workspaces(0).Databases(0) Set MainDB2 = DBEngine.Workspaces(0).Databases(0) DoCmd.RunMacro "Material Selections for Utilitzation" Refresh ' "Moving Parts to AS400" Set MainSet = MainDB.OpenRecordset("RMSFILES#_IEMUP1A0") ' Create dynaset. Set MainSet2 = MainDB2.OpenRecordset("Process by material") ' Create dynaset. ' "Purging AS400 product number file" On Error Resume Next MainSet.MoveFirst On Error GoTo 0 Do If Not (MainSet.EOF) Then MainSet.Delete DoEvents Else DoEvents Exit Do End If MainSet.MoveNext Loop ' "Purging AS400 result file" MainSet2.MoveFirst Do If Not (MainSet2.EOF) Then p$ = MainSet2!prt MainSet.AddNew MainSet!PRDNO = p$ MainSet.Update DoEvents Else DoEvents Exit Do End If MainSet2.MoveNext Loop ' lblstatus.Caption = "Activating AS400 Program" DoEvents ActiveXCtl24.DoClick ' "Retrieving Results" ' DoCmd.RunMacro "AS400 Utiliz Results" ' UtilResult1.SourceObject = "Util Result1" ' ' lblStatus.Caption = "Calculating material utilization on parts" ' lblstatus.Caption = "Done" ' Command133.Caption = Command133.Tag' End Sub ``` ## What it does **Command13_Click: Database Processing and AS400 Integration** ### Overview The `Command13_Click` subroutine is responsible for performing a series of database operations and integrating with an external system, specifically the AS400. This process involves: 1. Opening specific queries and tables 2. Moving parts from one database to another (RMSFILES#_IEMUP1A0) 3. Purging product number files from AS400 4. Activating AS400 programs 5. Refreshing the application ### Step-by-Step Breakdown #### Initialization * The subroutine sets up two databases (`MainDB` and `MainDB2`) as well as their respective recordsets (`MainSet` and `MainSet2`). * It also enables/disables certain buttons based on the current state of the application. #### Moving Parts to AS400 1. **Open RMSFILES#_IEMUP1A0 Query**: The subroutine opens a specific query called "Processes by material 2" using `DoCmd.OpenQuery`. This query is used to retrieve data from one database. 2. **Open Process by material Query**: Another query, "Process by material", is opened in the second database using `DoCmd.OpenTable`. 3. **Move Records and Purge AS400 Product Number File**: * The subroutine loops through each record in the first query (`MainSet`), deletes it from its original location, and adds a new record to the corresponding table in the second database (`MainSet2`). This process effectively moves data from one database to another while purging product number files from AS400. 4. **Activate AS400 Programs**: The subroutine simulates activating an external program called `ActiveXCtl24` by clicking on it using `DoEvents`. #### Refresh and Cleanup * After completing the above steps, the application refreshes itself using `Refresh`. * The subroutine then closes any open forms or queries. ### Error Handling Throughout the code, error handling is implemented using `On Error Resume Next` and `Err_CommandX_Click` handlers. These ensure that if an error occurs during execution, a message box will be displayed with the error description, and the application can continue running by resuming the normal error-handling flow. **Command16_Click: Material Upgrade Form** ### Overview The `Command16_Click` subroutine opens a specific form (`"14" + Chr$(34) + " Process Sheet"`), sets its record source to a query called `"Processes by material 4"`, and closes it using `DoCmd.Close`. ### Step-by-Step Breakdown 1. **Open Material Upgrade Form**: The subroutine opens the specified form. 2. **Set Record Source**: It sets the record source of the form to a specific query, `"Processes by material 4"`. 3. **Close Form**: Finally, it closes the form using `DoCmd.Close`. **Command2_Click: Process Material Upgrade** ### Overview The `Command2_Click` subroutine opens two specific queries (`"Processes by material 2"` and `"Processes by material 2a"`), calls another subroutine (`Command4_Click`) to perform some actions, and then closes the first query. ### Step-by-Step Breakdown 1. **Open Queries**: The subroutine opens both specified queries. 2. **Call Command4_Click**: It calls another subroutine (`Command4_Click`) to perform specific actions. 3. **Close First Query**: Finally, it closes the first opened query using `DoCmd.Close`. **Command3_Click: Material Selections for Utilitzation Macro** ### Overview The `Command3_Click` subroutine opens a form called `"14" + Chr$(34) + " Process Sheet"` and sets its record source to a specific query called `"Processes by material 3"`. It then closes the form using `DoCmd.Close`. ### Step-by-Step Breakdown 1. **Open Material Selections Form**: The subroutine opens the specified form. 2. **Set Record Source**: It sets the record source of the form to a specific query, `"Processes by material 3"`. 3. **Close Form**: Finally, it closes the form using `DoCmd.Close`. **Command4_Click: Material Selections for Utilitzation Macro** ### Overview The `Command4_Click` subroutine performs several database operations and integrates with an external system. ### Step-by-Step Breakdown 1. **Material Selections Macro**: The subroutine runs a specific macro called `"Material Selections for Utilitzation"`. 2. **Refresh Application**: It then refreshes the application using `Refresh`. This process is likely used to integrate various databases and perform operations that require external system integration, such as data transfer and synchronization. **Best Practices** 1. Error Handling: Implementing error handling mechanisms ensures that errors are caught and handled properly. 2. Code Organization: Organizing code into clear sections or procedures makes it easier to understand and maintain. 3. Comments and Documentation: Adding comments and documentation can improve the readability of the code, especially for complex processes. Note: This summary aims to provide a high-level overview of the `Command13_Click` subroutine and its related subroutines, focusing on the main steps involved in database processing and AS400 integration. The actual implementation may vary based on the specific requirements of the application.