Solved

Force table advance to a new record programmatically - MS Access

Posted on 2016-11-04
3
29 Views
Last Modified: 2016-11-04
MS Access:

I have a form with 2 subforms on it.  Both subforms are displayed as continuous forms.
Subform1’s record source is a table with transaction records.
Subform2’s record source is a ‘temporary’ table. I will wind up clearing it out at the end of each session.
Each record in Subform1 has a command button next to it.
The objective is to allow the user to select any record (s)he wants and to populate, one by one, Subform2 (or rather the temporary table displayed through Subform2). So, Subform2 can be viewed as an object used for creating a ‘list’ of selected records from the transactions table (displayed through Subform1).

The problem:
I need Subform2 (or its associated table) to advance to a new record after being populated with a selection from Subform1.  Without this functionality (and presuming the temporary table is empty at the start of all of this to make illustration easier), what is happening is when I make a second (or third or fourth, etc) record selection in Subform1, it is just overwriting the record displayed in Subform2.

This is my code under the command button in Subform1.  It does properly put a record into the temporary table.  But that one record keeps getting overwritten instead of records being added when multiple selections are made. You can see I have no code for ‘advancing’ to a new record, which is what I need:

Private Sub cmd_Select_Click()

On Error GoTo Err_cmd_Select_Click

Me.Parent.frm_Subform2.SetFocus
Me.Parent.frm_Subform2.Form.txt_Field1 = Me.txt_Field1
Me.Parent.frm_Subform2.Form.txt_Field2 = Me.txt_Field2
Me.Parent.frm_Subform2.Form.Dirty = False

Exit_cmd_Select_Click:
    Exit Sub

Err_cmd_Select_Click:
    MsgBox Err.Description
    Resume Exit_cmd_Select_Click
 End Sub

I should note that if I click in the ‘new record’ row of Subform2 and then make a second selection (presuming I already made one selection and therefore Subform2 now displays one record) from Subform1, the second selection gets properly added to the temporary table.  But I want to avoid having to click back and forth between subforms. I’d like to be able to control it all under the command buttons in Subform1
So, really all this question is is how to get the temporary table to ‘advance’ to accept a new (additional) record.

Thank you
0
Comment
Question by:dbfromnewjersey
  • 2
3 Comments
 
LVL 19

Accepted Solution

by:
Eric Sherman earned 500 total points
ID: 41874293
Try this ...

Me.Parent.frm_Subform2.SetFocus
If Me.Parent.frm_Subform2.NewRecord = False Then DoCmd.GoToRecord , , acNewRec
Me.Parent.frm_Subform2.Form.txt_Field1 = Me.txt_Field1
Me.Parent.frm_Subform2.Form.txt_Field2 = Me.txt_Field2
Me.Parent.frm_Subform2.Form.Dirty = False

ET
0
 

Author Comment

by:dbfromnewjersey
ID: 41874303
Thank you.
0
 
LVL 19

Expert Comment

by:Eric Sherman
ID: 41874325
Glad to help.

ET
0

Featured Post

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

810 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