Results 1 to 3 of 3
  1. #1
    Bkper087 is offline Advanced Beginner
    Windows 7 64bit Access 2016
    Join Date
    May 2014
    Posts
    81

    Popup form is not loading foreign key

    I've made many databases and maybe its just one of those days, but I'm going crazy.



    I have a subform (Form B) on my main form (Form A) that includes a button. This button opens a pop-up window. The popup window (Form C) has a foreign key field.

    Form B table includes FormBID (primary key) field.

    Form C includes FormCID (primary key) and FormBIDfk.

    What do I need to do to get the FormBIDfk field to autopopulate with the contents of FormBID when the form is opened? FormB will always be open when FormC is loaded. There is a one to many relationship set-up between FormB[FormBID] and FormC[FormBIDfk]

    Nothing is working.

  2. #2
    kd2017 is offline Well, I tried at least.
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Posts
    1,165
    I use OpenArgs.

    DoCmd.OpenForm has an optional parameter OpenArgs. Pass your FormBID to the pop up form with this paramter.

    Code:
    docmd.OpenForm "form name here", , , , acFormAdd, acDialog, me.formbid
    Then in form C's On Load event check to see if the form opened with OpenArgs, if so then set the default value of the foreign key field's control to the value passed to open args:

    Code:
    if not isnull(me.openargs) then
       me.formbidfk.defaultvalue = me.openargs
    else
       'no args passed to form. clear default value just in case.. maybe not necessary
       me.formbidfk.defaultvalue = ""
    end if
    https://docs.microsoft.com/en-us/off...docmd.openform

  3. #3
    accesstos's Avatar
    accesstos is offline Expert
    Windows XP Access 2007
    Join Date
    Dec 2018
    Location
    Greece
    Posts
    551
    Take a look at the attachment (events.zip) of this post.
    Maybe it covers your needs.

    Good luck!

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

Similar Threads

  1. Loading A Form
    By Robert2150 in forum Access
    Replies: 5
    Last Post: 06-24-2015, 01:38 PM
  2. Replies: 14
    Last Post: 08-23-2014, 12:35 PM
  3. loading empty form
    By Suzie2012 in forum Forms
    Replies: 5
    Last Post: 10-10-2012, 07:03 PM
  4. Replies: 10
    Last Post: 05-08-2012, 09:17 AM
  5. Replies: 2
    Last Post: 04-19-2012, 11:29 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