Solved

Parent and subform- On Current update record

Posted on 2016-08-24
5
23 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
  • 3
  • 2
5 Comments
 
LVL 34

Accepted Solution

by:
PatHartman earned 500 total points
Comment Utility
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
Comment Utility
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 34

Expert Comment

by:PatHartman
Comment Utility
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
Comment Utility
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 34

Expert Comment

by:PatHartman
Comment Utility
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

743 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now