Solved

Force table advance to a new record programmatically - MS Access

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

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

I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
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…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
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…

792 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