Results 1 to 7 of 7
  1. #1
    msmithtlh is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Mar 2013
    Posts
    151

    Calling a subform based on a condition

    My primary data table (call it table "A") has only a few fields, one of which is "category." For most of the categories, the data in table "A" is all that is needed. For one category, however, there are over 30 additional fields. Therefore I set up a separate table for this "extended" data (table "B") and created a one-to-one relationship on record id. All this is working fine for most of what I need (update forms, reports, etc.)

    I am attempting to create a data entry form for new records (only new records - separate form for updating), and I want to display the data from table "B" in a subform. Since this is for new records, a query isn't suitable for the data source. The main form for entering records for table "A" is working fine. How can I set up the subform to be "called" based on the category selected in the main form (table "A")? Based on one category, it needs to display the subform and create a new record in table "B" with the same record number as table "A.". I'm assuming this would need to be done with VBA code, and have made some attempts. My first (and I think biggest) problem is getting the record number assigned in table B to match the record number in table A. Also, getting the forms to display as a form/subform, not as 2 separate forms.

    Thanks in advance for all help!!

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,944
    Doesn't setting the Master/Child links properties of subform container synchronize the records?

    Set the subform container control Visible property to No.

    Code in the main form Current event as well as the category combobox AfterUpdate event:

    Me.subformcontainername.Visible = Me.category = "what is the category that applies?"

    Record in subform will be initiated when data is entered into any field of the new record line. This should also populate the foreign key field.
    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
    msmithtlh is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Mar 2013
    Posts
    151
    Looking through the properties on the subform, I don't see anything called Master/child links. Can you give some more details please on setting the links (where to find the properties, etc.) Thank you.

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,944
    Master/Child Links are properties of the subform container control. This control will be on the main form. The container can have a SourceObject of table, query, form, or report.
    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.

  5. #5
    msmithtlh is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Mar 2013
    Posts
    151
    I found the properties. However, because I am in an "add" mode, not an edit mode, after the record number on the main form (linked to table "A") fills in, I get a pop up error saying "The index or primary key cannot contain a null value." I've tried putting code on the properties of the record number in table "A" to transfer the value to the record number in table "B" but I keep getting the same error. If this were an update form, I wouldn't have this problem.

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,944
    I have suspicions of what cause of issue is but could take forever to talk our way through it. Might want to provide db for analysis. Follow instructions at bottom of my post.
    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.

  7. #7
    msmithtlh is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Mar 2013
    Posts
    151
    I found what I needed in another post and got it working. Thanks for your help!!!

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

Similar Threads

  1. Add Query Based on if Condition
    By shakeelmscw in forum Queries
    Replies: 17
    Last Post: 01-18-2013, 02:35 AM
  2. Hide field in sub-report based on condition
    By vinsavant in forum Reports
    Replies: 4
    Last Post: 12-16-2012, 10:18 AM
  3. Printing multiple reports at once based on condition
    By justinwright in forum Reports
    Replies: 24
    Last Post: 04-13-2011, 01:40 PM
  4. Update 2 fields based on where condition.
    By Confused in forum Access
    Replies: 2
    Last Post: 11-19-2009, 05:21 PM
  5. Highlighting Report Data Based on a Condition
    By KramerJ in forum Reports
    Replies: 1
    Last Post: 05-29-2009, 10:27 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