Solved

Force table advance to a new record programmatically - MS Access

Posted on 2016-11-04
3
14 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

Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

Join & Write a Comment

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…
In the article entitled Working with Objects – Part 1 (http://www.experts-exchange.com/Microsoft/Development/MS_Access/A_4942-Working-with-Objects-Part-1.html), you learned the basics of working with objects, properties, methods, and events. In Work…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

758 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

14 Experts available now in Live!

Get 1:1 Help Now