?
Solved

Populate Subform table

Posted on 2014-04-07
4
Medium Priority
?
527 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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
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…
Suggested Courses

743 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