Results 1 to 6 of 6
  1. #1
    Bcanfield83 is offline Advanced Beginner
    Windows 7 32bit Access 2016
    Join Date
    May 2018
    Posts
    81

    Question This *should* be easy, right?? (RE: Sub-Forms)

    Hi All,


    I'm working on a Project Tracking form in my database. My goal is to have a main form and then a few sub-forms embedded on that form. But only 1 sub-form will be visible at a time.
    On the main form is a Combo Box which contains a listing of Projects.
    What I'm trying to do is set up the form so that once a Project is selected from the Combo Box, one of the sub-forms will update and contain the information pertinent to that project. But I can't seem to get it to work.. I've tried a couple things and either the sub-form simply does nothing (e.g.: I select a project from the Combo Box, but the related Text Boxes on the Sub-Form remain blank), or I get some type of Primary Key error. So, clearly I must not be linking the correct

    Main Form is bound to tblProjects. The Combo Box contains the fields below in this table, though only the PROJECT_NAME field is actually visible in the Combo Box. Column 1 (PROJECT_ID) is the bound column. I have a hidden text box on the form that the PROJECT_ID # is bound to.

    tblProjects:
    PROJECT_ID (Auto-Number) - Primary Key
    PROJECT_NAME (Text)

    One of the Sub-Forms is bound to tblProject_Tasks. The PT_PROJECT_ID field corresponds with the PROJECT_ID field in the above table. Thus - in the Sub-Form properties, I'm using PROJECT_ID under "Link Master Fields", and PT_PROJECT_ID under "Link Child Fields".
    In theory, this should work.. right?
    All I'm looking to do is have the Sub-Form contain the listing of Project Tasks (Text Boxes) upon that Project being selected from the Combo Box on the Main Form.
    Now obviously there's probably a much easier way to do this on a single form as opposed to using main form/sub-form, but I also am planning on having another Sub-Form for the purpose of entering a New Project, another one with stakeholder/project team info, etc.

    tblProject_Tasks:
    PT_TASK_ID (Auto-Number) - Primary Key
    PT_PROJECT_ID (Number) --> joins to PROJECT_ID in tblProjects (Many to One relationship).
    PT_TASK1 (Text)
    PT_TASK2 (Text)
    PT_TASK3 (Text)

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,523
    tblProject_Tasks table is not normalized.
    you only need 1 PT_TASK (Text) field.
    cause 1 project can have many tasks.

  3. #3
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,898
    The combobox must be UNBOUND (no ControlSource) otherwise you are trying to change data in record. What code is used to filter or GoTo the selected project?

    Don't use a subform for entering new project. Go to new record row on the main form.
    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.

  4. #4
    Bcanfield83 is offline Advanced Beginner
    Windows 7 32bit Access 2016
    Join Date
    May 2018
    Posts
    81
    Quote Originally Posted by ranman256 View Post
    tblProject_Tasks table is not normalized.
    you only need 1 PT_TASK (Text) field.
    cause 1 project can have many tasks.
    Duh - good point. Not sure what I was thinking there. The sad thing is I actually had 10 "PT_TASK" fields but I only listed 3...

  5. #5
    Bcanfield83 is offline Advanced Beginner
    Windows 7 32bit Access 2016
    Join Date
    May 2018
    Posts
    81
    I was able to get most of this setup as intended. My record source on the Main Form is pulling from tblProjects, where PROJECT_ID is equal to [Forms]![frmProject_Management_Main].[lstProjects]
    [lstProjects] is the List Box control - now unbound. When you click on the Project from this list, it loads the related Task Info from tblProject_Tasks in a sub-form (linking PROJECT_ID from the main form to PT_PROJECT_ID in the sub-form).
    I still can't for the life of me figure out how to ADD a new Project via the Main Form.. so I added a button which opens up a separate form (frmNew_Project).
    The user enters the Project Name and Description in this form, then clicks "Submit" button. The Submit Button has the following code which inserts that new project into the table. I'm sure there's a better/smarter way to do this though.

    Code:
    Private Sub btnAddProj_Click()
    
    
    Dim strProjName As String
    Dim strProjDesc As String
    Dim strSQL As String
    Me.txtProjName.SetFocus: strProjName = Me.txtProjName.Value 'Project Name
    Me.txtProjDesc.SetFocus: strProjDesc = Me.txtProjDesc.Value 'Project Description
    
    
    
    
    strSQL = "INSERT INTO tblProjects (PROJECT_NAME, PROJECT_DESC)" & _
            "VALUES ('" & strProjName & "', '" & strProjDesc & "')"
    
    
    DoCmd.RunSQL strSQL
    
    
    DoCmd.Close acForm, "frmNew_Project", acSaveNo
    
    
    Forms![frmProject_Management_Main]![lstProjects].Requery
    
    
    MsgBox "Project Has Been Added"

  6. #6
    Bcanfield83 is offline Advanced Beginner
    Windows 7 32bit Access 2016
    Join Date
    May 2018
    Posts
    81
    Oops, sorry for the duplicate post.

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

Similar Threads

  1. Must be an easy way
    By eddcole in forum Forms
    Replies: 2
    Last Post: 01-03-2017, 01:23 PM
  2. I Bet this is an EASY Fix!!!
    By Z1nkstar in forum Access
    Replies: 10
    Last Post: 06-06-2014, 10:32 AM
  3. Replies: 1
    Last Post: 03-15-2012, 02:21 PM
  4. Replies: 0
    Last Post: 03-29-2011, 09:37 AM
  5. I know this has to be easy...
    By MelindaP in forum Access
    Replies: 7
    Last Post: 08-20-2010, 02:15 PM

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