Solved

Parent and subform- On Current update record

Posted on 2016-08-24
5
40 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 35

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 35

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 35

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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

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…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Familiarize people with the process of utilizing SQL Server functions 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 Ac…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…

773 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