Results 1 to 12 of 12
  1. #1
    geebsterlove is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2013
    Posts
    5

    How do I automatically populate some fields of a New Record

    Hi guys,


    I'm new here and looking for some help with an MS Access form. Right now I have a database that keeps track of employees, their projects, and the time frame during which they work on certain projects. I currently have a combo box for EmployeeID and SprintID (the time frame) which work together to filter a subform that lists projects.

    I'd like to have a button on my form to Add New Records. I'd like the new records to automatically populate the SprintID and EmployeeID fields of the subform with the values I select in the combo boxes of the main form. I think I need a button with an On Click event? I am unsure how to code such an event.

    Any help is appreciated! Thanks!

    Amy

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    If the EmployeeID and SprintID were the LinkMaster/ChildFields of the SubForm control then they would be populated by Access for you when you start a new record in the SubForm.

  3. #3
    geebsterlove is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2013
    Posts
    5
    Oh okay, great. Setting the LinkMaster/ChildFields worked to populate the subform fields with values, but they are not the correct values. It also messed with how my combo box filter works. I want all records to show in the subform until I select values from my SprintID and EmployeeID combo boxes. With LinkMaster/ChildFields defined, I only see one new record upon opening my form.

  4. #4
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Then populate them in the AfterUpdate event of the ComboBox.

  5. #5
    geebsterlove is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2013
    Posts
    5
    Sorry, RG, not quite sure I understand. Right now my AfterUpdate looks like this. (Note: Sorry, "EmployeeID" as stated above is actually "PersonnelID"):

    HTML Code:
    Private Sub cboSprintID_AfterUpdate()
    ' Set the Personnel combo box to be limited by the selected SprintID
    Me.cboPersonnelID.RowSource = "SELECT DISTINCT tblTimeEntry.PersonnelID, tblTimeEntry.SprintID FROM tblTimeEntry " & _
        " WHERE SprintID = " & Nz(Me.cboSprintID) & _
        " ORDER BY PersonnelID"
    Me.cboPersonnelID = Null
    
    
    'enable cboPersonnelID
    EnableControls
    ApplyFilter
    
    End Sub
    
    
    Private Sub cboPersonnelID_AfterUpdate()
    
        ApplyFilter
        
    End Sub
    And my subform is being filtered by the following:

    HTML Code:
    Private Sub ApplyFilter()
    Dim strFilter As String
    strFilter = ""
    ' see if there is data in cboSprintID, if so add it to the filter
    If Me!cboSprintID & vbNullStr <> vbNullStr Then   
    strFilter = strFilter & " AND [tblTimeEntry.SprintID] = " & Me.cboSprintID
    End If
    If Me!cboPersonnelID & vbNullStr <> vbNullStr Then   
    strFilter = strFilter & " AND [tblTimeEntry.PersonnelID] = " & Me.cboPersonnelID & " "
    End If
    
    If strFilter <> "" Then   
    ' trim off leading "AND"   
    frmProjectPercent.Form.Filter = Mid(strFilter, 5)   
    frmProjectPercent.Form.FilterOn = True
    Else   
    frmProjectPercent.Form.Filter = ""   
    frmProjectPercent.Form.FilterOn = False
    
    End If
    End Sub
    How do I get all records to display in my subform until I make a selection in my SprintID combobox while SprintID and PersonnelID are my LinkMaster/Child Fields?

  6. #6
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Using the LinkChild and LinkMaster properties of the SubForm control, you do not need the filters. Are you willing to try that?

  7. #7
    geebsterlove is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2013
    Posts
    5
    Okay, so I got rid of the filter and set the LinkChild and LinkMaster properties, but I'm still not getting the result I want. The subform will only show records for the first SprintID. How do I get it to show all records in the table?

  8. #8
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Initially the LinkChildField and LinkMasterField properties should be blank. Does that give you all of the records?

  9. #9
    geebsterlove is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2013
    Posts
    5
    Yes, when LinkChild/MasterFields are blank, the subform shows all records.

  10. #10
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    There are lots of ways to skin this cat. I'm thinking 2 invisible TextBoxes on the Main form filled in by the AfterUpdate event of the ComboBox.
    Will the SubForm always be limited to PersonnelID and SprintID values? What is the name of your SubFormControl? The control with the LinkChild/MasteFields properiies on it.

  11. #11
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    I'm pretty sure you can have the LinkChildFields property populated and as long as the LinkMasterFields property is blank or points to blank fields then you will see all of the SubForm recordset.

  12. #12
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    It has been pretty quiet on this thread. I hope that means you were successful with your task.

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

Similar Threads

  1. Replies: 1
    Last Post: 06-04-2012, 12:43 AM
  2. fields automatically filled in a new record
    By fabiobarreto10 in forum Forms
    Replies: 9
    Last Post: 04-09-2012, 05:18 PM
  3. Replies: 3
    Last Post: 10-17-2011, 10:36 PM
  4. Replies: 5
    Last Post: 05-18-2011, 08:57 AM
  5. Replies: 2
    Last Post: 04-20-2011, 06:59 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