Solved

Populate Subform table

Posted on 2014-04-07
4
521 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
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 500 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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
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…

860 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