163 lines
5.0 KiB
Markdown
163 lines
5.0 KiB
Markdown
# Sorted by Machine old
|
|
Analysis generated on: 4/1/2025 4:01:48 PM
|
|
---
|
|
## Record Source
|
|
- *None*
|
|
## Controls
|
|
| Control Name | Reference |
|
|
|--------------|-----------|
|
|
| Machine Name (Row Source) | [[Tables/[MachineNames];]] |
|
|
## VBA Code
|
|
```vba
|
|
|
|
|
|
Private Sub Command2_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)
|
|
Command2.Tag = Command2.Caption
|
|
Command2.Caption = "Processing"
|
|
Edit_Table.Enabled = False
|
|
|
|
' DoEvents
|
|
' lblstatus.Caption = "Selecting Parts for Material Utilization"
|
|
'DoCmd.RunMacro "Material Selections for Utilitzation"
|
|
'lblstatus.Caption = "Selection Complete"
|
|
Refresh
|
|
lblstatus.Caption = "Moving Parts to AS400"
|
|
Set MainSet = MainDB.OpenRecordset("RMSFILES#_IEMUP1A0") ' Create dynaset.
|
|
Set MainSet2 = MainDB2.OpenRecordset("Sorted By Machines 1") ' 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!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
|
|
|
|
lblstatus.Caption = "Retrieving Results"
|
|
UtilResult2.SourceObject = "tricks"
|
|
DoCmd.RunMacro "AS400 Utiliz Results for steve"
|
|
UtilResult2.SourceObject = "Util Result2"
|
|
lblstatus.Caption = "Calculating material utilization on parts"
|
|
lblstatus.Caption = "Done"
|
|
Command2.Caption = Command2.Tag
|
|
Edit_Table.Enabled = True
|
|
|
|
End Sub
|
|
|
|
Private Sub Machine_Name_BeforeUpdate(Cancel As Integer)
|
|
Command2.Enabled = False
|
|
DoCmd.SetWarnings (False)
|
|
|
|
DoCmd.OpenQuery "Sort by Machine"
|
|
DoCmd.SetWarnings (True)
|
|
Command2.Enabled = True
|
|
End Sub
|
|
Private Sub Edit_Table_Click()
|
|
On Error GoTo Err_Edit_Table_Click
|
|
|
|
Dim stDocName As String
|
|
Dim MyForm As Form
|
|
|
|
stDocName = "Util Selection C1"
|
|
Set MyForm = Screen.ActiveForm
|
|
|
|
DoCmd.OpenTable stDocName, acViewNormal
|
|
|
|
Exit_Edit_Table_Click:
|
|
Exit Sub
|
|
|
|
Err_Edit_Table_Click:
|
|
MsgBox Err.Description
|
|
Resume Exit_Edit_Table_Click
|
|
|
|
End Sub
|
|
|
|
Private Sub Refresh_Click()
|
|
UtilResult2.SourceObject = "tricks"
|
|
UtilResult2.SourceObject = "Util Result2"
|
|
|
|
End Sub
|
|
```
|
|
## What it does
|
|
**VBA Code Description**
|
|
========================
|
|
|
|
### Overview
|
|
|
|
This VBA code is used to automate a process of material utilization for parts in an inventory management system. It interacts with an Access database, an AS400 server, and various forms to collect and process data.
|
|
|
|
### Command2_Click Procedure
|
|
|
|
This procedure is triggered when the user clicks on the "Command2" button. Its primary function is to initiate the material utilization process by:
|
|
|
|
1. Setting up database connections and recordsets.
|
|
2. Purging the AS400 product number file.
|
|
3. Moving parts to the AS400 server.
|
|
4. Activating an AS400 program.
|
|
5. Retrieving results from the AS400 server.
|
|
6. Calculating material utilization on parts.
|
|
|
|
**Step-by-Step Breakdown:**
|
|
|
|
* Connects to the database and sets up recordsets for "RMSFILES#_IEMUP1A0" and "Sorted By Machines 1".
|
|
* Purges the AS400 product number file by deleting records from the first recordset.
|
|
* Moves parts to the AS400 server by adding new records to the second recordset with the corresponding part numbers.
|
|
* Activates an AS400 program using `ActiveXCtl24.DoClick`.
|
|
* Retrieves results from the AS400 server using a macro.
|
|
* Calculates material utilization on parts.
|
|
|
|
### Machine_Name_BeforeUpdate Procedure
|
|
|
|
This procedure is used to restrict user input when editing the "Machine Name" field. It disables the "Command2" button and sets warnings to false while opening the "Sort by Machine" query. Once the query is closed, it re-enables the "Command2" button.
|
|
|
|
### Edit_Table_Click Procedure
|
|
|
|
This procedure is triggered when the user clicks on the "Edit Table" button. Its primary function is to:
|
|
|
|
1. Open the specified table ("Util Selection C1") in edit mode.
|
|
2. If any errors occur during editing, it displays an error message and exits.
|
|
|
|
### Refresh_Click Procedure
|
|
|
|
This procedure is used to refresh the data in the "Util Result2" form. It simply sets the source object of `UtilResult2` to "tricks" or "Util Result2".
|
|
|
|
**Key Features:**
|
|
|
|
* Interacts with Access database, AS400 server, and various forms.
|
|
* Automates material utilization process using macros and recordsets.
|
|
* Restricts user input when editing machine names.
|
|
* Handles errors during table editing and refreshes data in the "Util Result2" form.
|