Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Parent and subform- On Current update record

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

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 40

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 40

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying 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

The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
In a use case, a user needs to close an opened report by simply pressing the Escape (Esc) key. This can be done by adding macro code in Report_KeyPress or Report_KeyDown event.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Enter Foreign and Special Characters Enter characters you can't find on a keyboard using its ASCII code ... and learn how to make a handy reference for yourself using Excel ~ Use these codes in any Windows application! ... whether it is a Micr…
Suggested Courses

578 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