Solved

Force table advance to a new record programmatically - MS Access

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
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…

732 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