Results 1 to 9 of 9
  1. #1
    CharlieK is offline Novice
    Windows 10 Access 2010 64bit
    Join Date
    Oct 2016
    Posts
    15

    First Record of the Sub form Gets Replaced with a Different Record

    Hello,



    I have a subform in my database in datasheet view. This is subform is located on a main form (let's call it Form 01) along with a text box to search and filter one of the fields on the subform. When a user double clicks on a record on the subform, another form (call it Form 02) pops up. This Form 02 has fields to show the record data user clicked on and some additional information. My issue is, every time I double click on a record on the subform, that specific record replaces the first record in the subform. I checked the code and I am not updating any data fields on the subform. Can you please help?

    Thank you!

  2. #2
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    Please post the code in the On double event, so we can we what it is you are actually doing. Note too that when you double-click an item, the On Click event also fires. Do you have any code in the On Click event?

    Is there any code in the popup Form 02?

  3. #3
    CharlieK is offline Novice
    Windows 10 Access 2010 64bit
    Join Date
    Oct 2016
    Posts
    15
    Hi John-G,

    Below is the code I have on Form 01. This code is on a field on the subform itself. So when a user double clicks on this specific field, Form 02 Pops up. There is no code on Click event on either Form 01 or the subform. No code on Form 02 as well.

    Private Sub ProcessID_DblClick(Cancel As Integer)


    DoCmd.OpenForm "frmProcessDetails"


    Forms!frmProcessDetails!txtPDProcessID = Me!ProcessID
    Forms!frmProcessDetails!txtPDAffiliationName = Me!AffiliationName
    Forms!frmProcessDetails!txtPDProcessStep = Me!ProcessStep
    Forms!frmProcessDetails!txtPDProcessDescription = Me!ProcessDescription
    Forms!frmProcessDetails!txtPDProcessComments = Me!ProcessComments
    Forms!frmProcessDetails!txtPDAffiliationID = Me!AffiliationID
    Forms!frmProcessDetails!txtPDDecisionID = Me!DecisionID


    Forms!frmProcessDetails.Requery


    End Sub



    Thank you!

  4. #4
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    Does frmProcessDetails have a table or query as a record source? If it does, then that is the problem. As soon as you open it, you are immediately changing all the fields to the data from the record in in the main form, so whatever record frmProcessDetails opens with gets changed as well.

  5. #5
    CharlieK is offline Novice
    Windows 10 Access 2010 64bit
    Join Date
    Oct 2016
    Posts
    15
    frmProcessDetails is the pop up form. This only has some text boxes which get populated from the record data the user clicks on. The Subform is a query. but that is the form which gets changed when the user clicks on a record. How can I fix this?

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    If the pop up form is bound to the same data, the first record will be changed as John pointed out. If you're trying to edit the record, this may be appropriate:

    BaldyWeb wherecondition
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    CharlieK is offline Novice
    Windows 10 Access 2010 64bit
    Join Date
    Oct 2016
    Posts
    15
    Hi,

    Let me explain what I am trying to do here. I think that will help you to give me a better solution.

    I have a Form with a subform (datasheet view) and a text field. This subform's record source is a query. based on what and how I want to show on the subform, I don't think anything other than a query would work (but open for suggestions). When the user clicks on a record on the subform, the record data should open on a pop up form in a single form format. On this second form, addition to the fields to show the record data, I want to add a tab control and on each tab a subform. The data for subforms on each tab should depend on the field values on the pop-up form. How can I do this? Is there another way to achieve this?

    Click image for larger version. 

Name:	Img01.PNG 
Views:	13 
Size:	39.6 KB 
ID:	26323

  8. #8
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    I see what your trying to do, and the concept is reasonable. I assume your screen shot is of Form02. That form, Form02, DOES have a query or table as its record source, because it is showing 1 of 8 in the navigation bar at the bottom.

    So, going back to your original question - when you open the form, it is going to display a record from its record source. Your code then changes the values in several controls on this form, which has the effect of modifying whatever record the form is displaying (assuming the controls on the form are bound to fields in the form's record source).

    To open the form to the correct record, i.e. the one you want to view, you need to add a WHERE parameter to the openform command:

    DoCmd.OpenForm "frmProcessDetails",,,"ProcessID = " & Me!ProcessID

    which will allow you to view/edit the correct record.

    If you have bound the controls on Form02 to fields in the record source, and you have correctly linked the subforms to those controls, I can't see why it would not work.
    Last edited by John_G; 11-03-2016 at 04:27 PM. Reason: Restore proper formatting

  9. #9
    CharlieK is offline Novice
    Windows 10 Access 2010 64bit
    Join Date
    Oct 2016
    Posts
    15
    Hi John,

    You were right. I had accidentally linked some of the fields on form 02 to a record source. which in order was replacing the first record. Once I unbound those fields, form worked perfectly.

    Thank you so much!

    Charlie.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 4
    Last Post: 07-21-2015, 02:50 PM
  2. Replies: 6
    Last Post: 02-02-2015, 02:14 PM
  3. Replies: 3
    Last Post: 03-09-2013, 10:39 AM
  4. Replies: 3
    Last Post: 10-19-2012, 04:30 PM
  5. Replies: 3
    Last Post: 08-26-2012, 10:04 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums