?
Solved

Force table advance to a new record programmatically - MS Access

Posted on 2016-11-04
3
Medium Priority
?
42 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
[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
3 Comments
 
LVL 19

Accepted Solution

by:
Eric Sherman earned 2000 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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses

764 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