Results 1 to 6 of 6
  1. #1
    jfn15 is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    26

    Code to move to new record, taking a value from previous record

    I have three tables with M:M relationship.

    TBLApp - AppID and other fields
    TBLAnimals - AnimalID and other fields
    TBLAppSpecies - AppID, AnimalID and other fields - this is the junction table

    First form based on tblApp
    Second form based on junction table, with a subform based on tblAnimals

    Presently I have a command button the application form that open the second form, to the AppID on the first form.
    DoCmd.OpenForm "frmAppSpecies",,,,,,Me.AppID
    How do I then allow the user to add another record that is also related to that AppID, without going back to the first form and reclicking the command button?



    I know this would be simpler using a subform in the application form, but I've been directed that this is not what the boss wants!

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    You could set the DefaultValue property of the AppID textbox of the opened form. What is the code that extracts the AppID from OpenArgs and populates the first record? Put code to set the DefaultValue property in that same procedure.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    You're already using the OpenArgs argument to pass the AppID to the second Form, so simply use it again when you add additional Records for that ID in that session of the second Form:

    Code:
    Private Sub Form_Current()
     If Me.NewRecord Then
      If Nz(Me.OpenArgs, "") <> "" Then
         Me.AppID = Me.OpenArgs
      End If
     End If
    End Sub


    Linq ;0)>
    Last edited by Missinglinq; 06-14-2013 at 09:15 AM.
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  4. #4
    jfn15 is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    26
    Hi Linq, thanks so much for your reply. That works well for adding a new record, however once the second form has more than one record (i.e if it was a subform, you would see several related records), I need to be able to open that second form (called frmAppSpecies) to show all the related animal records from the application form. So, say we have an application for 7 different animal species, the user can open the second form and have all the related species information there to edit, one page (species) at a time. To explain, each species may also have several related individual animal records (gender, microchip number etc - a 4th table, linked to tblAppspecies. These records are entered into a subform in frmAppSpecies (subfrmAnimaldetails). Does that make sense??? So, on frmApplication we need to see each species that is listed on the app., and on frmAppSpecies we need to see details about individuals within that species (for each application). I'm very new to this so I often make simple errors that may seem obvious to others, but that leave me quite perplexed. I do hope my explanation doesn't leave you similarly confused!

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    So need to have option to open form to view existing species records related to an application?

    DoCmd.OpenForm "formname", , , "ApplicationID=" & Me.ApplicationID
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  6. #6
    jfn15 is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    26
    .... and it would be useful if I actually engaged my brain before seeking assistance!!!!\

    Many thanks - got it!

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

Similar Threads

  1. Replies: 8
    Last Post: 07-06-2013, 05:13 PM
  2. Replies: 22
    Last Post: 06-12-2012, 10:02 PM
  3. Replies: 1
    Last Post: 04-10-2012, 06:00 PM
  4. Replies: 3
    Last Post: 11-23-2011, 12:25 AM
  5. Replies: 1
    Last Post: 07-25-2011, 09:41 AM

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