Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Parent and subform- On Current update record

Posted on 2016-08-24
5
Medium Priority
?
63 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 39

Accepted Solution

by:
PatHartman earned 2000 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 39

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 39

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

610 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