# Scott's Utilization of C6-C9 Analysis generated on: 4/1/2025 4:07:47 PM --- ## Record Source - *None* ## Controls | Control Name | Reference | |--------------|-----------| | *None* | - | ## VBA Code ```vba Option Compare Database Private Sub Command0_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 = "Selecting Parts for Scott" Refresh lblstatus.Caption = "Moving Parts to AS400" Set MainSet = MainDB.OpenRecordset("RMSFILES#_IEMUP1A0") ' Create dynaset. Set MainSet2 = MainDB2.OpenRecordset("Scott'sQ3") ' 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 lblstatus.Caption = "Purging AS400 result file" MainSet2.MoveFirst Do If Not (MainSet2.EOF) Then p$ = MainSet2!parts 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 lblstatus.Caption = "Retrieving Results" ' UtilResult1.SourceObject = "tricks" DoCmd.OpenQuery "Scott'sQ4" ' UtilResult1.SourceObject = "Util Result1" ' lblStatus.Caption = "Calculating material utilization on parts" lblstatus.Caption = "Done" End Sub ``` ## What it does **VBA Code Description** ======================== ### Overview This VBA code is designed to automate a series of tasks related to part management and data transfer between Microsoft Access databases. The code is triggered by a click event on a command button (Command0) in an Access form. ### Code Structure The code consists of several sections, each responsible for a specific task: 1. **Initialization** * Sets up the database connections and recordsets. 2. **Data Purging** * Moves data from one table to another, purging the target table of duplicates. 3. **Data Transfer** * Transfers data from another table to the first table, using a product number file as a reference. 4. **AS400 Program Activation** * Triggers an action in an external system (AS400) by clicking a button on the form. 5. **Results Retrieval** * Opens a query to retrieve results from the Access database. ### Detailed Breakdown #### Initialization ```markdown Option Compare Database Private Sub Command0_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) ``` The code sets up two database connections (`MainDB` and `MainDB2`) and creates recordsets for each. #### Data Purging ```markdown lblstatus.Caption = "Selecting Parts for Scott" Refresh lblstatus.Caption = "Moving Parts to AS400" Set MainSet = MainDB.OpenRecordset("RMSFILES#_IEMUP1A0") ' Create dynaset. Set MainSet2 = MainDB2.OpenRecordset("Scott'sQ3") ' Create dynaset. MainSet.MoveFirst Do If Not (MainSet.EOF) Then MainSet.Delete DoEvents Else DoEvents Exit Do End If MainSet.MoveNext Loop ``` The code moves data from the `RMSFILES#_IEMUP1A0` table in `MainDB` to the `Scott'sQ3` table in `MainDB2`, purging duplicates. #### Data Transfer ```markdown lblstatus.Caption = "Purging AS400 product number file" On Error Resume Next MainSet.MoveFirst On Error GoTo 0 Do If Not (MainSet.EOF) Then p$ = MainSet!parts MainSet.AddNew MainSet!PRDNO = p$ MainSet.Update DoEvents Else DoEvents Exit Do End If MainSet.MoveNext Loop ``` The code transfers data from the `RMSFILES#_IEMUP1A0` table in `MainDB2` to the first table, using a product number file as a reference. #### AS400 Program Activation ```markdown lblstatus.Caption = "Activating AS400 Program" DoEvents ActiveXCtl24.DoClick ``` The code activates an action in an external system (AS400) by clicking a button on the form. #### Results Retrieval ```markdown lblstatus.Caption = "Retrieving Results" ' UtilResult1.SourceObject = "tricks" ' lblStatus.Caption = "Calculating material utilization on parts" DoCmd.OpenQuery "Scott'sQ4" ' ... (no further code executed) ``` The code opens a query to retrieve results from the Access database. ### Conclusion This VBA code automates a series of tasks related to part management and data transfer between Microsoft Access databases. The code is designed to be robust and flexible, handling errors and edge cases as needed.