Results 1 to 2 of 2
  1. #1
    Awesome! is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Dec 2014
    Posts
    10

    Launch new record child form with 2 foreign keys pre-populated


    Hi,

    I am building a database which has a main table that contains patient demographics and then child tables which contains clinic visits. There are many kinds of clinic visits (TB, HIV, CD4, VL) so I didn't use subforms in this case.

    I managed to create several buttons on the main demographics form that open a pop-up child form to a new record and linked to that patient.

    There are two IDs that I am working with. One is a national ID (NID) and one is an ID we have created internally from my organization (OID). There is always a unique OID for the patient but not all patients have a NID.

    When I open the child forms I get a blank NID and OID. I would like in the new record for the NID to be prepopulated with the associated/blank NID in the parent form and then do the same with the OID.

    It would be good if the data encoder accidentally clicks the button to the child form, that the pre-populated fields won't keep the record with the remaining fields blank (I get this kind of error when pre-populating fields in Epi Info).

    How would I go about coding this?

    Thanks,


    Awesome!

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,644
    Two things you want to happen and both are fairly common topics:

    1. pass data to the opening form - several ways to do this, one is code in the opening form that refers to the main form - however, I don't see need to store the NID into the dependent table.

    If Me.NewRecord Then
    Me!OID = Forms.mainformname!OID
    End If

    2. give user opportunity to cancel the record - since you require every field to have data (except NID), one way is to set every field as required in table, then Access can nag the user if they screw up, otherwise, code in the form BeforeUpdate event would have to check every field for data and if any one is empty, take appropriate action
    https://www.accessforums.net/program...put-48582.html
    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.

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

Similar Threads

  1. Extracting Foreign Keys
    By QuantifyRisk in forum Forms
    Replies: 7
    Last Post: 08-08-2014, 02:05 PM
  2. Query with Foreign Keys
    By BawdyB in forum Queries
    Replies: 5
    Last Post: 05-15-2013, 06:47 PM
  3. Child Record Created, but won't display in child form
    By CementCarver in forum Programming
    Replies: 1
    Last Post: 04-10-2013, 12:42 PM
  4. primary/foreign keys
    By st1300 in forum Database Design
    Replies: 38
    Last Post: 12-04-2011, 01:27 PM
  5. Need help with foreign keys
    By acdougla17 in forum Access
    Replies: 1
    Last Post: 09-26-2011, 03:50 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