Solved

Parent and subform- On Current update record

Posted on 2016-08-24
5
50 Views
Last Modified: 2016-08-25
Experts, I have a parent (frmParent) and subform (sub1) and they are linked by ID's as found in the properties.  
I enter details in the parent such as currency (its a cbo) and DrawDate.  After I enter the details on the parent, I go to the sub and want the same values to be inserted (for a new record but also to update for not a new record).  it seems like I am having a refresh issue because the "new record" line in the subform seems to no longer appear after I click on it but the values seem to update tho but I just cant add more records.  If I hit the F5 button, I will see the "new record" line appear again and I can add just a single record but will need to hit F5 once again to add another record.  

I do have If me.dirty = false in the On Dirty event of the subform but that doesnt refresh like the F5 button.

Sub1:
Private Sub Form_Current()
            Me.Currency = Me.Parent.Currency
            Me.ValueDate = Me.Parent.DrawDate
            Me.Refresh 'this doesnt seem to refresh like F5
    End If
End Sub


Not sure if is is clear.  Let me know if you need additional clarification.
Grateful for your help.

here is a screen print:
Parent_sub
0
Comment
Question by:pdvsa
[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
  • 3
  • 2
5 Comments
 
LVL 37

Accepted Solution

by:
PatHartman earned 500 total points
ID: 41769195
If the two fields in the parent table apply to ALL rows in the child table then they should exist only in the parent table and not be copied to the child table.

1. remove the record save code from the on Dirty event.  The Dirty event fires as soon as a single character is entered into the form.  That is not typically an appropriate time to save a record.  Access will ALWAYS automatically save a dirty record when you leave it.  That is enough for most people.  Occasionally, the user wants to force a save and in that case, give him a save button that saves the record if it is dirty.
2. The Current event is not a good choice for a non-user initiated update.  The best event to "copy" data from a parent record is the Form's BeforeInsert event or the Form's on Dirty event depending on whether you only want to force the update for new rows or if you want to do it for all rows.  If what you are trying to do is to force an update on a record when the user clicks into it, I still don't like using the Current event since it fires whenever a record obtains the focus.  I would use either the click event of a button or the double click event of a control.  Both of those are conscious actions and will not be done accidentally.
3. Occasionally the new record row is not visible due to how the form is scrolled.  You can always go to it by pressing the yellow * in the navigation bar.
0
 

Author Comment

by:pdvsa
ID: 41769271
thank you.  
I put that code on BeforeInsert and it seems to work fine now.   Havent tested completely though but I think its the solution.  

thank you for the help and great explanation
0
 
LVL 37

Expert Comment

by:PatHartman
ID: 41769373
You're welcome.  I would have preferred that you not duplicated the data since that violates second normal form but getting the code into the correct event is a start.
0
 

Author Comment

by:pdvsa
ID: 41769660
Ahhh i did not  think about that.  Sometimes i think that when the data is properly normalized one has to be an expert to develop the queries to extract.  Thank you again for that tip
0
 
LVL 37

Expert Comment

by:PatHartman
ID: 41770606
You also have to consider what happens if you change the value in the parent record.  Is it OK for the parent record to have a different currency or draw date?  If it isn't, you see the real issue because you now have created a data anomaly.  That is why the data should not be stored in multiple places.
0

Featured Post

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
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.
Familiarize people with the process of utilizing SQL Server stored procedures 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 Micr…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

734 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