Here's the code:
Here are the comments, What is missing is the intent.
ChatGPT:
"
This code is written in VBA and is a subroutine that runs when the cmdImportRaw button is clicked. The first thing it does is check if the variable "pubOrdersID" is null, and if it is, it displays a message box saying "Select Order" and exits the subroutine.
Next, it runs two SQL statements: the first is a DELETE statement that deletes records from the "tblBomImportRaw" table where the "rbOrdersID" field matches the value of the "getOrdersID()" function. The second is an INSERT INTO statement that inserts records into the "tblBomImportRaw" table from the "xlsBillOfMaterialsBom" table.
Then it declares a variable "strID" and sets it to "0", and runs a SELECT statement that selects records from the "tblBomImportRaw" table where the "rbOrdersID" field matches the value of the "getOrdersID()" function, and orders the records by the "RawBomID" field. The results of this query are used to populate a DAO recordset object, which is then used to iterate through the records, updating the "rbDrawingObjectType" field with the value of the "strID" variable. Finally, it closes the recordset and sets it to nothing."
Code:
Private Sub cmdImportRaw_Click()
If IsNull(pubOrdersID) Then
MsgBox ("Select Order")
Exit Sub
End If
strSQL = "DELETE tblBomImportRaw.RawBomID, tblBomImportRaw.rbOrdersID " & vbCrLf & _
"FROM tblBomImportRaw " & vbCrLf & _
"WHERE (((tblBomImportRaw.rbOrdersID)=getOrdersID()));"
CurrentDb.Execute strSQL, dbFailOnError + dbSeeChanges
strSQL = "INSERT INTO tblBomImportRaw ( rbID, rbLogDate, rbOrdersID, rbSubCategory, rbFloor, rbManufacturer, rbCode, rbSize, rbDescription, rbCount, rbExtra, rbUnit, rbComment, rbLabel, rbUserID ) " & vbCrLf & _
"SELECT xlsBillOfMaterialsBom.ID, Now() AS Expr2, getOrdersID() AS Expr1, xlsBillOfMaterialsBom.[Sub Category], xlsBillOfMaterialsBom.Floor, xlsBillOfMaterialsBom.Manufacturer, xlsBillOfMaterialsBom.Code, xlsBillOfMaterialsBom.Size, xlsBillOfMaterialsBom.Description, xlsBillOfMaterialsBom.Count, xlsBillOfMaterialsBom.Extra, xlsBillOfMaterialsBom.Unit, xlsBillOfMaterialsBom.Comment, xlsBillOfMaterialsBom.Label, getUserID() AS Expr3 " & vbCrLf & _
"FROM xlsBillOfMaterialsBom;"
CurrentDb.Execute strSQL, dbFailOnError + dbSeeChanges
Dim strID As String
strID = "0"
strSQL = "SELECT tblBomImportRaw.RawBomID, tblBomImportRaw.rbID, tblBomImportRaw.rbOrdersID, tblBomImportRaw.rbDrawingObjectType " & vbCrLf & _
"FROM tblBomImportRaw " & vbCrLf & _
"WHERE (((tblBomImportRaw.rbOrdersID)=getOrdersID())) " & vbCrLf & _
"ORDER BY tblBomImportRaw.RawBomID;"
Dim Rs As DAO.Recordset
Set Rs = CurrentDb.OpenRecordset(strSQL)
Rs.Edit
If Rs.RecordCount > 0 Then
Rs.MoveFirst
Do Until Rs.EOF
If IsNull(Rs!rbID) Then
strID = "0"
Else
If strID = "0" Then
strID = Rs!rbID
Rs.Edit
Rs!rbDrawingObjectType = strID
Rs.Update
Else
Rs.Edit
Rs!rbDrawingObjectType = strID
Rs.Update
End If
End If
Debug.Print strID
Rs.MoveNext
Loop
Rs.Close
Set Rs = Nothing
End If
End Sub
Here are the comments, What is missing is the intent.
ChatGPT:
"
This code is written in VBA and is a subroutine that runs when the cmdImportRaw button is clicked. The first thing it does is check if the variable "pubOrdersID" is null, and if it is, it displays a message box saying "Select Order" and exits the subroutine.
Next, it runs two SQL statements: the first is a DELETE statement that deletes records from the "tblBomImportRaw" table where the "rbOrdersID" field matches the value of the "getOrdersID()" function. The second is an INSERT INTO statement that inserts records into the "tblBomImportRaw" table from the "xlsBillOfMaterialsBom" table.
Then it declares a variable "strID" and sets it to "0", and runs a SELECT statement that selects records from the "tblBomImportRaw" table where the "rbOrdersID" field matches the value of the "getOrdersID()" function, and orders the records by the "RawBomID" field. The results of this query are used to populate a DAO recordset object, which is then used to iterate through the records, updating the "rbDrawingObjectType" field with the value of the "strID" variable. Finally, it closes the recordset and sets it to nothing."
Last edited: