?
Solved

Populate Subform table

Posted on 2014-04-07
4
Medium Priority
?
529 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 12

Expert Comment

by:pdebaets
ID: 39983974
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
ID: 39983982
The forms are unbound, so I can't use LinkChildFields
0
 
LVL 12

Accepted Solution

by:
pdebaets earned 2000 total points
ID: 39984004
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
ID: 39984020
Thank you for your assistance - this has done the trick
0

Featured Post

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
Make the most of your online learning experience.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Introduction to Processes
Suggested Courses

649 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