Hi there, I'm pleased to announce that duplicating a record which has a primary key which is NOT autonumber CAN be done using the inputbox method.
I still get the warning about it not wanting to paste etc, (I'm sure one of the forum gurus can tell me how to make it stop), but it does in fact copy the record with the new primary key typed into the inputbox.
This is the code behind the copy record button:
Private Sub Command151_Click()
On Error GoTo Err_Command151_Click
DoCmd.SetWarnings False
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 2, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 5, , acMenuVer70 'Paste Append
Me.IDNO = (InputBox(IDNO, "Enter IDNO"))
DoCmd.SetWarnings True
Exit_Command151_Click:
Exit Sub
Err_Command151_Click:
MsgBox Err.Description
Resume Exit_Command151_Click
End Sub
I have the following code behind the actual primary key field on my form:
Private Sub IDNO_BeforeUpdate(Cancel As Integer)
DoCmd.SetWarnings False
If DCount("[IDNO]", "ValuationJob", "[IDNO] = '" & Me.IDNO & "'") > 0 Then
Me.IDNO.Undo
MsgBox "That number already exists", vbOKOnly
End If
End Sub
Ipexues: you mention having the same problem and that the combo boxes are interfering with the copy. I had that too, my combo boxes are record finders, but it only seems to happen if there are actual values in the fields, in other words I had done a search on a record before trying to copy. They are not interfering in the record copy if they are cleared.