Solved

Populate Subform table

Posted on 2014-04-07
4
515 Views
Last Modified: 2014-04-07
Hi,

I have a form with a subform (table) on.  The main form is unbound.  

I am using the subform (table) to allow the user to enter data, however, I need to auto populate two fields on the table everytime a new record is created.  I have the following code on the subform but nothing is happening:

Private Sub Form_BeforeInsert(Cancel As Integer)
Dim rst As DAO.Recordset

Set rst = CurrentDb.OpenRecordset("tbl_reference_data", dbOpenTable)
rst.AddNew
rst!customer_id = Me.Parent!txt_customer_id
rst!batch_id = Me.Parent!txt_batch_id
rst!date_stamp = Now()
rst.Update
'rst.Close
Set rst = Nothing

End Sub

Open in new window

0
Comment
Question by:anthonytr
  • 2
  • 2
4 Comments
 
LVL 12

Expert Comment

by:pdebaets
Comment Utility
Try setting the Link Child Fields subform property to "customer_id, batch_id" (without the quotes), and do the same for Link Parent Fields. Then you don't need the code you have posted above.

You may need to set the Link Parent Fields property to "txt_customer_id, txt_batch_id", but try "customer_id, batch_id" first.
0
 

Author Comment

by:anthonytr
Comment Utility
The forms are unbound, so I can't use LinkChildFields
0
 
LVL 12

Accepted Solution

by:
pdebaets earned 500 total points
Comment Utility
You may want to consider binding your parent form. It can make life much easier.

Another option is to set the default value of your subform customer_id and batch_id controls. You could set them to

=forms!MyParentFormName!txt_customer_id

and

=forms!MyParentFormName!txt_batch_id

... respectively.
0
 

Author Closing Comment

by:anthonytr
Comment Utility
Thank you for your assistance - this has done the trick
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

The purpose of this article is to demonstrate how we can use conditional statements using Python.
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now