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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

New Record in form to create new Record in subform

Status
Not open for further replies.

jojomore

Technical User
May 22, 2001
10
0
0
US
I have a form/subform that I want to use not only to display related info (which works fine), but to add/edit records. The main form is "Product Number Info", subform "Product Images". When a new product number is added to the main form you have to re-type the product number in the subform. How can I eliminate the duplicate data entry?
 
Hi

Have you set the Master/Child link field properties of the sub form control?, sounds like they should be set to ProductNumber

Regards

Ken Reay
Freelance Solutions Developer
Boldon Information Systems Ltd
Website needs upgrading, but for now - UK
 
"Product Images" has a DataSource that is really a query which has an underlying table. Open that table and set the foreign key to the value you wish. A foreign key is usuall the ID key of the main form. Make you own Add Record cmd button on the Main Form. In its code include the following.

DIM rs as DAO.recordset ' reference mdDOS 3.6 needs checked

set rs = currentdb.openrecordset("SUBSTable")

rs.addnew
rs("KeyValue") = me.KeyValue
rs.update
rs.close

set rs = nothing
forms![MainForm]![SubForm].requery

exit sub

rollie@bwsys

if you need a sample, email me.
 
KenReay: The Master/child links are there. The forms work for existing records.

rollie@bwsys: I guess I do need a sample...the following is the code that I came up with when adding the add record button to the main form and trying to add your code. The underlying tables have a one to one relationship on the Product_Number field.
I get an error saying "You tried to assign the Null value to a variable that is not a Variant data type."

Private Sub Add_Part_Number_Click()
On Error GoTo Err_Add_Part_Number_Click

DoCmd.GoToRecord , , acNewRec

Dim rs As DAO.Recordset
Set rs = CurrentDb.OpenRecordset("dbo_08_Product_Numbers")

rs.AddNew
rs("Product_Number") = Me.Product_Number
rs.Update
rs.Close

Exit_Add_Part_Number_Click:
Exit Sub

Err_Add_Part_Number_Click:
MsgBox Err.Description
Resume Exit_Add_Part_Number_Click

End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top