Hi
I have an access database which has various related tables. I have parts which have many operations, each operation could have many sub operations and each sub operation has a timing record attached to it.
What the user wants my vb app to do is to select a part on my parts maintenance screen and choose a "copy" menu option. This facility needs to copy the part selected, prompt the user for a new part number but have all of the original parts operation, sub ops, etc copied to new records.
At present, my routine copies the selected part and propts for a new part number and saves it to the database. It doesn't however, copy any related table data from the original part record. Is there an easy way to do this without having a load of recordsets opening, looping and writing to the database? I know there is a recordset clone option but this doesn't seem to clone any related table data.
Here's my code so far...
Private Sub UpdatePart()
On Error GoTo Err_Log
Dim Message, Title
Set db = New Connection
db.CursorLocation = adUseClient
db.Open DataBaseCON 'open the database connection
Dim OpRS As Recordset
Message = "Enter New Part Number"
Title = "Duplicate Part: " & adoPrimaryRS.Fields(2) 'part number
varPartNo = InputBox(Message, Title) 'new part number is now stored in varPartNo
If vbCancel = True Then 'cancel the copy record operation
Exit Sub 'drop out of routine
End If
varDesc = txtFields(0) 'description is stored in varDesc
varPID = txtFields(2) 'product id is now stored in varPID
db.Execute " INSERT INTO Parts ([PartID],[Description],[ProdID]) VALUES ('" & varPartNo & "', '" & varDesc & "', '" & varPID & "');" 'update part table with duplicate record
Err_Log:
'MsgBox Err.Number & " " & Err.Description, vbCritical, "Error"
Resume Next
End Sub
Thanks
Andrew
I have an access database which has various related tables. I have parts which have many operations, each operation could have many sub operations and each sub operation has a timing record attached to it.
What the user wants my vb app to do is to select a part on my parts maintenance screen and choose a "copy" menu option. This facility needs to copy the part selected, prompt the user for a new part number but have all of the original parts operation, sub ops, etc copied to new records.
At present, my routine copies the selected part and propts for a new part number and saves it to the database. It doesn't however, copy any related table data from the original part record. Is there an easy way to do this without having a load of recordsets opening, looping and writing to the database? I know there is a recordset clone option but this doesn't seem to clone any related table data.
Here's my code so far...
Private Sub UpdatePart()
On Error GoTo Err_Log
Dim Message, Title
Set db = New Connection
db.CursorLocation = adUseClient
db.Open DataBaseCON 'open the database connection
Dim OpRS As Recordset
Message = "Enter New Part Number"
Title = "Duplicate Part: " & adoPrimaryRS.Fields(2) 'part number
varPartNo = InputBox(Message, Title) 'new part number is now stored in varPartNo
If vbCancel = True Then 'cancel the copy record operation
Exit Sub 'drop out of routine
End If
varDesc = txtFields(0) 'description is stored in varDesc
varPID = txtFields(2) 'product id is now stored in varPID
db.Execute " INSERT INTO Parts ([PartID],[Description],[ProdID]) VALUES ('" & varPartNo & "', '" & varDesc & "', '" & varPID & "');" 'update part table with duplicate record
Err_Log:
'MsgBox Err.Number & " " & Err.Description, vbCritical, "Error"
Resume Next
End Sub
Thanks
Andrew