Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

copy mainform with subform and text type primary key

Status
Not open for further replies.

acnovice

Programmer
Jan 27, 2005
100
US
From Customer Inquiry form, I want to copy mainForm frmCustInqPOLog2 with subform sfrmInqSubTBL1. There are QNo fields which are text type on mainform and subform and they are Primary Key as well (table InquiryLog and InqSubTBL1).

When I click "Duplicate" command btn from main form, I want to copy all fields but QNo. I want the user put new QNo and changed some data from copied form and save it as a new record.

I set the QNo field as a text type. The reason is that I want to put new QNos like 100A, 100B from original 100.

When I click duplicate btn, I'm getting following error.
"Index or primary key cannot contain a a Null Value."

I'm using following code and put Append Query.

Code:
Private Sub btnDuplicate_Click()

Dim dbs As DAO.Database
Dim Rst As DAO.Recordset
Dim F As Form

Set dbs = CurrentDb
Set Rst = Me.RecordsetClone

On Error GoTo Err_btnDuplicate_Click

Me.Tag = Me![QNo]

' Add new record to end of Recordset object.
With Rst
   .AddNew
      !InqDate = Me!InqDate
      !CustomerName = Me!CustomerName
      !producType = Me!producType
      !InOut = Me!InOut
      !totalWatt = Me!totalWatt
      !Agency = Me!Agency
      !Urgency = Me!Urgency
      !Status = Me!Status
   .Update   ' Save changes.
   .Move 0, .LastModified
End With
Me.Bookmark = Rst.Bookmark

DoCmd.SetWarnings False
DoCmd.OpenQuery "Duplicate Customer Inquiry"
DoCmd.SetWarnings True

Me![sfrmInqSubTBL1].Requery

Exit_btnDuplicate_Click:
Exit Sub

Err_btnDuplicate_Click:
MsgBox Error$
Resume Exit_btnDuplicate_Click:
End Sub

Append Query:
INSERT INTO InqSubTBL1 ( VendorName, TPbaseNo, Spec, priceQty, Note)
SELECT InqSubTBL1.VendorName, InqSubTBL1.TPbaseNo, InqSubTBL1.Spec, InqSubTBL1.priceQty, InqSubTBL1.Note, Cstr(Forms!frmCustInqPOLog2!QNo) AS NewQNo
FROM InqSubTBL1
WHERE (((InqSubTBL1.QNo)=[Forms]![frmCustInqPOLog2].[Tag]));

Any help will be appreciated.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top