E
Eka1618
This Message is for Allen Browne, However I need help ASAP, so if anyone
knows a solutions, it would be greatly appreciated if you could pass it on.
I have used your method for duplicating a form and all of it subforms. This
has worked well for each subform except for one (frmPattern).
The record source for this particular subform is tblPattern whose primary
key is a composite PK.
PAT_NO (pk)
PAT_SIZE (pk)
REQUEST_NO (pk/fk)
QUANTITY
I think I am close to a solution, but it will not duplicate this subform
record Access says the value for PAT_NO cannot be NULL. There is a value in
all of the fields I am trying to copy at the time I click this button.
Tom van Stiphout Has tried to help me with this, but no luck yet. The
following is what I have so far. Everything else is working except for when I
try to duplicate frmPattern.
Private Sub cmdDupe_Click()
'On Error GoTo Err_Handler
'Purpose: Duplicate the main form record and related records in the
subform.
Dim strSql As String 'SQL statement.
Dim lngID As Long 'Primary key value of the new record.
'Save and edits first
If Me.Dirty Then
Me.Dirty = False
End If
'Make sure there is a record to duplicate.
If Me.NewRecord Then
msgbox "Select the record to duplicate."
Else
'Duplicate the main record: add to form's clone.
With Me.RecordsetClone
.AddNew
!TITLE = Me.TITLE
!EMP_ID = Me.lboRequestor.Value
!REQUESTEE = Me.lboRequestee.Value
!DUE_DATE = Me.DUE_DATE
!CUSTOMER = Me.CUSTOMER
!NOTES = Me.NOTES
!R_TYPE = Me.R_TYPE
.Update
'Save the primary key value, to use as the foreign key for the
related records.
.Bookmark = .LastModified
lngID = !REQUEST_NO
'Duplicate the related records: append query.
If Me.subDupKey.Form.RecordsetClone.RecordCount > 0 Then
strSql = "INSERT INTO tblKey( REQUEST_NO, K_PART_NO,
K_EWO_NO, K_SKID_NO, K_MAT_HEAT, K_MAT_TYPE, K_PLAT, K_TOP_COAT, K_HEX,
K_HARD_VALUE ) " & _
"SELECT " & lngID & " As NewK_ID, K_PART_NO, K_EWO_NO,
K_SKID_NO, K_MAT_HEAT, K_MAT_TYPE, K_PLAT, K_TOP_COAT, K_HEX, K_HARD_VALUE "
& _
"FROM tblKey WHERE REQUEST_NO = " & Me.REQUEST_NO & ";"
DBEngine(0)(0).Execute strSql, dbFailOnError
End If
If Me.subDupLock.Form.RecordsetClone.RecordCount > 0 Then
strSql = "INSERT INTO tblLock( REQUEST_NO, L_PART_NO,
LOCK_LUG, LUG_TOOL, L_EWO_NO, L_SKID_NO, L_MAT_HEAT, L_MAT_TYPE, L_PLAT,
L_TOP_COAT, L_THREAD, L_HARD_VALUE ) " & _
"SELECT " & lngID & " As NewL_ID, L_PART_NO, LOCK_LUG,
LUG_TOOL, L_EWO_NO, L_SKID_NO, L_MAT_HEAT, L_MAT_TYPE, L_PLAT, L_TOP_COAT,
L_THREAD, L_HARD_VALUE " & _
"FROM tblLock WHERE REQUEST_NO = " & Me.REQUEST_NO & ";"
DBEngine(0)(0).Execute strSql, dbFailOnError
End If
If Me.frmPattern.Form.RecordsetClone.RecordCount > 0 Then
strSql = "INSERT INTO tblPattern( QUANTITY ) " & _
"SELECT QUANTITY FROM tblPattern WHERE REQUEST_NO = " &
Me.REQUEST_NO & _
" AND PAT_NO = " & Me.frmPattern.Form.PAT_NO & " AND
PAT_SIZE = '" & Me.frmPattern.Form.PAT_SIZE & "';"
DBEngine(0)(0).Execute strSql, dbFailOnError
End If
Me.subDupGeneral.Form.Dirty = False
Me.subDupImpact.Form.Dirty = False
Me.subDupHandle.Form.Dirty = False
Me.subDupOffset.Form.Dirty = False
Me.subDupProof.Form.Dirty = False
Me.subDupStatic.Form.Dirty = False
Me.subDupSecurity.Form.Dirty = False
Me.subDupTorque.Form.Dirty = False
strSql = "INSERT INTO tblTest( REQUEST_NO, TEST_TYPE, UNITS,
A_M, SAMPLE_NO, PROVIDED, CYCLE_NO, CYCLE_TIME, TEST_TORQ, WRENCH_NO, RPM,
LOAD, MIN_LOAD, ACID, STRAIGHT_FAIL, INC_FAIL, START_PT, INCREMENT,
INSTALL_TRQ, MIN_TORQ, TRQ_SHUTOFF, TRQ_PT1, TRQ_PT2, TRQ_PT3, TRQ_PT4,
TRQ_PT5, TRQ_PT6, DWELL_ON, DWELL_OFF, WHEEL, WHEEL_NO, TEST_WASHER,
STUD_PER_TEST, STUD_PT_NO, CUST_SPEC, SHROUD, LPS, TAKE_TO_FAILURE,
BOTH_DIRECTIONS, DESCRIPTION, LOOKOUT ) " & _
"SELECT " & lngID & " As NewTEST_ID, TEST_TYPE, UNITS, A_M,
SAMPLE_NO, PROVIDED, CYCLE_NO, CYCLE_TIME, TEST_TORQ, WRENCH_NO, RPM, LOAD,
MIN_LOAD, ACID, STRAIGHT_FAIL, INC_FAIL, START_PT, INCREMENT, INSTALL_TRQ,
MIN_TORQ, TRQ_SHUTOFF, TRQ_PT1, TRQ_PT2, TRQ_PT3, TRQ_PT4, TRQ_PT5, TRQ_PT6,
DWELL_ON, DWELL_OFF, WHEEL, WHEEL_NO, TEST_WASHER, STUD_PER_TEST, STUD_PT_NO,
CUST_SPEC, SHROUD, LPS, TAKE_TO_FAILURE, BOTH_DIRECTIONS, DESCRIPTION,
LOOKOUT " & _
"FROM tblTest WHERE REQUEST_NO = " & Me.REQUEST_NO & ";"
DBEngine(0)(0).Execute strSql, dbFailOnError
'Display the new duplicate.
Me.Bookmark = .LastModified
End With
End If
Exit_Handler:
Exit Sub
Err_Handler:
msgbox "Error " & Err.Number & " - " & Err.DESCRIPTION, , "cmdDupe_Click"
Resume Exit_Handler
End Sub
I think I am having trouble because of the composite PK's. If you have any
suggestions please let me know, Thank You!
knows a solutions, it would be greatly appreciated if you could pass it on.
I have used your method for duplicating a form and all of it subforms. This
has worked well for each subform except for one (frmPattern).
The record source for this particular subform is tblPattern whose primary
key is a composite PK.
PAT_NO (pk)
PAT_SIZE (pk)
REQUEST_NO (pk/fk)
QUANTITY
I think I am close to a solution, but it will not duplicate this subform
record Access says the value for PAT_NO cannot be NULL. There is a value in
all of the fields I am trying to copy at the time I click this button.
Tom van Stiphout Has tried to help me with this, but no luck yet. The
following is what I have so far. Everything else is working except for when I
try to duplicate frmPattern.
Private Sub cmdDupe_Click()
'On Error GoTo Err_Handler
'Purpose: Duplicate the main form record and related records in the
subform.
Dim strSql As String 'SQL statement.
Dim lngID As Long 'Primary key value of the new record.
'Save and edits first
If Me.Dirty Then
Me.Dirty = False
End If
'Make sure there is a record to duplicate.
If Me.NewRecord Then
msgbox "Select the record to duplicate."
Else
'Duplicate the main record: add to form's clone.
With Me.RecordsetClone
.AddNew
!TITLE = Me.TITLE
!EMP_ID = Me.lboRequestor.Value
!REQUESTEE = Me.lboRequestee.Value
!DUE_DATE = Me.DUE_DATE
!CUSTOMER = Me.CUSTOMER
!NOTES = Me.NOTES
!R_TYPE = Me.R_TYPE
.Update
'Save the primary key value, to use as the foreign key for the
related records.
.Bookmark = .LastModified
lngID = !REQUEST_NO
'Duplicate the related records: append query.
If Me.subDupKey.Form.RecordsetClone.RecordCount > 0 Then
strSql = "INSERT INTO tblKey( REQUEST_NO, K_PART_NO,
K_EWO_NO, K_SKID_NO, K_MAT_HEAT, K_MAT_TYPE, K_PLAT, K_TOP_COAT, K_HEX,
K_HARD_VALUE ) " & _
"SELECT " & lngID & " As NewK_ID, K_PART_NO, K_EWO_NO,
K_SKID_NO, K_MAT_HEAT, K_MAT_TYPE, K_PLAT, K_TOP_COAT, K_HEX, K_HARD_VALUE "
& _
"FROM tblKey WHERE REQUEST_NO = " & Me.REQUEST_NO & ";"
DBEngine(0)(0).Execute strSql, dbFailOnError
End If
If Me.subDupLock.Form.RecordsetClone.RecordCount > 0 Then
strSql = "INSERT INTO tblLock( REQUEST_NO, L_PART_NO,
LOCK_LUG, LUG_TOOL, L_EWO_NO, L_SKID_NO, L_MAT_HEAT, L_MAT_TYPE, L_PLAT,
L_TOP_COAT, L_THREAD, L_HARD_VALUE ) " & _
"SELECT " & lngID & " As NewL_ID, L_PART_NO, LOCK_LUG,
LUG_TOOL, L_EWO_NO, L_SKID_NO, L_MAT_HEAT, L_MAT_TYPE, L_PLAT, L_TOP_COAT,
L_THREAD, L_HARD_VALUE " & _
"FROM tblLock WHERE REQUEST_NO = " & Me.REQUEST_NO & ";"
DBEngine(0)(0).Execute strSql, dbFailOnError
End If
If Me.frmPattern.Form.RecordsetClone.RecordCount > 0 Then
strSql = "INSERT INTO tblPattern( QUANTITY ) " & _
"SELECT QUANTITY FROM tblPattern WHERE REQUEST_NO = " &
Me.REQUEST_NO & _
" AND PAT_NO = " & Me.frmPattern.Form.PAT_NO & " AND
PAT_SIZE = '" & Me.frmPattern.Form.PAT_SIZE & "';"
DBEngine(0)(0).Execute strSql, dbFailOnError
End If
Me.subDupGeneral.Form.Dirty = False
Me.subDupImpact.Form.Dirty = False
Me.subDupHandle.Form.Dirty = False
Me.subDupOffset.Form.Dirty = False
Me.subDupProof.Form.Dirty = False
Me.subDupStatic.Form.Dirty = False
Me.subDupSecurity.Form.Dirty = False
Me.subDupTorque.Form.Dirty = False
strSql = "INSERT INTO tblTest( REQUEST_NO, TEST_TYPE, UNITS,
A_M, SAMPLE_NO, PROVIDED, CYCLE_NO, CYCLE_TIME, TEST_TORQ, WRENCH_NO, RPM,
LOAD, MIN_LOAD, ACID, STRAIGHT_FAIL, INC_FAIL, START_PT, INCREMENT,
INSTALL_TRQ, MIN_TORQ, TRQ_SHUTOFF, TRQ_PT1, TRQ_PT2, TRQ_PT3, TRQ_PT4,
TRQ_PT5, TRQ_PT6, DWELL_ON, DWELL_OFF, WHEEL, WHEEL_NO, TEST_WASHER,
STUD_PER_TEST, STUD_PT_NO, CUST_SPEC, SHROUD, LPS, TAKE_TO_FAILURE,
BOTH_DIRECTIONS, DESCRIPTION, LOOKOUT ) " & _
"SELECT " & lngID & " As NewTEST_ID, TEST_TYPE, UNITS, A_M,
SAMPLE_NO, PROVIDED, CYCLE_NO, CYCLE_TIME, TEST_TORQ, WRENCH_NO, RPM, LOAD,
MIN_LOAD, ACID, STRAIGHT_FAIL, INC_FAIL, START_PT, INCREMENT, INSTALL_TRQ,
MIN_TORQ, TRQ_SHUTOFF, TRQ_PT1, TRQ_PT2, TRQ_PT3, TRQ_PT4, TRQ_PT5, TRQ_PT6,
DWELL_ON, DWELL_OFF, WHEEL, WHEEL_NO, TEST_WASHER, STUD_PER_TEST, STUD_PT_NO,
CUST_SPEC, SHROUD, LPS, TAKE_TO_FAILURE, BOTH_DIRECTIONS, DESCRIPTION,
LOOKOUT " & _
"FROM tblTest WHERE REQUEST_NO = " & Me.REQUEST_NO & ";"
DBEngine(0)(0).Execute strSql, dbFailOnError
'Display the new duplicate.
Me.Bookmark = .LastModified
End With
End If
Exit_Handler:
Exit Sub
Err_Handler:
msgbox "Error " & Err.Number & " - " & Err.DESCRIPTION, , "cmdDupe_Click"
Resume Exit_Handler
End Sub
I think I am having trouble because of the composite PK's. If you have any
suggestions please let me know, Thank You!