Results 1 to 3 of 3
  1. #1
    Ramtrap is offline Advanced Beginner
    Windows 7 64bit Access 2016
    Join Date
    Dec 2016
    Posts
    62

    Link two forms together

    Hi All,



    I think I must really be missing something because I'm having the most difficult time getting what should probably be very simple to work.

    On a basic level, as an example, I have two tables:
    tbl_NameAge: (NameID <primary key>, myName, Age)
    tbl_LivesIn: (LocationID <primary key>, City, State, NameID <as foreign key>)

    I realize I'm probably already wrong right off the bat, putting the NameID field in the LivesIn table, but please bear with me.

    What I want is to create forms based off the tbl_NameAge and tbl_LivesIn tables.

    I want to install a button on the tbl_NameAge form whereby on_click I want it to open the tbl_LivesIn form. From there, I want the two forms to marry up (hence why I was thinking to add the NameID field in both tables).

    How do I write the vba so that these two forms will talk to each other? When I created it as a macro and I converted to VBA, the line of code it gave me is:

    Docmd.OpenForm "tbl_LivesIn", acNormal, "", "[NameID]=" [&ID], , acNormal

    However, when I click, I get a syntax error.

    What I'd ultimately like to have is a method to relate to other forms, but only to add that information when necessary (for example, I could create a "FavoriteTeam" or "Job" form).

    Lastly, I know I can put this into a query and have the information requested, and build the form off that query, but I get no joy from that, either.

    Can anyone tell me what I'm doing wrong?RelateFormsTest.accdb

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,521
    2 forms DO talk to one another, the Parent/Child form. They are both in 1 form synced together.
    It does no good to have 2 separate forms and try to sync them.

    put the sub form inside the parent form and set the
    LINK MASTER FIELDS
    LINK CHILD FIELDS

    but your example, you missed the ampersand on ID:

    Docmd.OpenForm "tbl_LivesIn", , , "[NameID]=" & [ID]

    THE FORM SHOULD BE NAMED: frm
    _LivesIn
    not tbl_LivesIn

  3. #3
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Here is your dB set up with main form/sub form...

    Look at field names... See how the main form/sub form are connected... Have fun....
    Attached Files Attached Files

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

Similar Threads

  1. Link Tables and Forms
    By trident in forum Forms
    Replies: 1
    Last Post: 05-07-2016, 05:24 AM
  2. link 2 or 3 forms
    By Mariapaiva in forum Database Design
    Replies: 4
    Last Post: 05-27-2014, 04:26 AM
  3. Link 2 forms
    By AussieGal in forum Access
    Replies: 5
    Last Post: 02-14-2013, 09:19 PM
  4. Replies: 5
    Last Post: 03-15-2012, 09:46 AM
  5. Link to Forms
    By Luke in forum Forms
    Replies: 1
    Last Post: 07-14-2011, 08:51 AM

Tags for this Thread

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