Results 1 to 11 of 11
  1. #1
    Stephenson is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Sep 2015
    Location
    North West
    Posts
    110

    Use multi select list box to populate multiple fields

    Hello all,

    I'm trying my best to create an employee attendance form. I would like to have a multi select list box with the employee's names that users can select. The names would then be stored in table, TcEmployee in field EmployeeID and the current date would populate the field DateWorked. Is it possible to split the selections from a list box into individual fields? If so I would greatly appreciate any advice on how to accomplish this.

    Thanks for taking a look,

    John

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    Multi select lists require programming.
    But if you use single select lists, add an append query to the dbl-click event.
    then this can add each person to the attendance table.

  4. #4
    Stephenson is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Sep 2015
    Location
    North West
    Posts
    110
    Paul this is just what I'm looking for. Thank you for the help.

    Have a great day,
    John

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Happy to help John!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    Stephenson is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Sep 2015
    Location
    North West
    Posts
    110
    The link pbaldy was excellent and now has me adding entries from a list box directly to my table, but I would like a bit more help. I have my list box on an unbound form with a subform (continuous format) displaying my entries. I would like my subform to requery when entries are made from the list box as well as fill in the current date in textbox txtDateWorked. I'm using the following code with no success.

    Code:
    Private Sub cmdAddRecords_Click()  Dim strSQL        As String
      Dim db            As DAO.Database
      Dim rs            As DAO.Recordset
      Dim ctl           As Control
      Dim varItem       As Variant
    
    
      On Error GoTo ErrorHandler
    
    
      Set db = CurrentDb()
      Set rs = db.OpenRecordset("tcEmployee", dbOpenDynaset, dbAppendOnly)
    
    
      'make sure a selection has been made
      If Me.lstEmployee.ItemsSelected.Count = 0 Then
        MsgBox "Must select at least 1 employee"
        Exit Sub
      End If
    
    
    '  If Not IsNumeric(Me.txtOtherValue) Then
    '    MsgBox "Must enter numeric Other Value"
    '    Exit Sub
    '  End If
    
    
      'add selected value(s) to table
      Set ctl = Me.lstEmployee
      For Each varItem In ctl.ItemsSelected
        rs.AddNew
        rs!EmployeeID = ctl.ItemData(varItem)
    '    rs!OtherValue = Me.txtOtherValue
        rs.Update
      Next varItem
    
    
    ExitHandler:
      Set rs = Nothing
      Set db = Nothing
      Exit Sub
    
    
    ErrorHandler:
      Select Case Err
        Case Else
          MsgBox Err.Description
          DoCmd.Hourglass False
          Resume ExitHandler
      End Select
    Me.sfrmTandAList.[txtDateWorked] = Date
    Me.sfrmTandAList.Form.Requery
    End Sub
    I've tried several variations to this with no luck. Could someone show me what I'm missing? The parent form is unbound and there is no link between the two forms.

    Thanks for having a look,

    John

  7. #7
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    If you want the date in the new data, use the line you commented out for OtherValue. I would expect the requery to work.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  8. #8
    Stephenson is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Sep 2015
    Location
    North West
    Posts
    110
    Thank you pbaldy. I will give this a shot.
    I'm not sure why the requery isn't working. I'll keep playing with it.

    Have a great night and thanks again for the help,

    John

  9. #9
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    No problem, post back if you get stuck.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  10. #10
    Stephenson is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Sep 2015
    Location
    North West
    Posts
    110
    Will do pbaldy.

    Looks like I just had my requery event in the wrong place. The following code works like a charm.

    Code:
    Private Sub cmdAddRecords_Click()  Dim strSQL        As String
      Dim db            As DAO.Database
      Dim rs            As DAO.Recordset
      Dim ctl           As Control
      Dim varItem       As Variant
    
    
      On Error GoTo ErrorHandler
    
    
      Set db = CurrentDb()
      Set rs = db.OpenRecordset("tcEmployee", dbOpenDynaset, dbAppendOnly)
    
    
      'make sure a selection has been made
      If Me.lstEmployee.ItemsSelected.Count = 0 Then
        MsgBox "Must select at least 1 employee"
        Exit Sub
      End If
    
    
    '  If Not IsNumeric(Me.txtOtherValue) Then
    '    MsgBox "Must enter numeric Other Value"
    '    Exit Sub
    '  End If
    
    
      'add selected value(s) to table
      Set ctl = Me.lstEmployee
      For Each varItem In ctl.ItemsSelected
        rs.AddNew
        rs!EmployeeID = ctl.ItemData(varItem)
        rs!DateWorked = Date
        rs.Update
      Next varItem
    Me.sfrmTandAList.Form.Requery
    
    
    ExitHandler:
      Set rs = Nothing
      Set db = Nothing
      Exit Sub
    
    
    ErrorHandler:
      Select Case Err
        Case Else
          MsgBox Err.Description
          DoCmd.Hourglass False
          Resume ExitHandler
      End Select
    
    
    End Sub
    Thanks again for all the help,
    John

  11. #11
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Sorry, didn't notice it was in the error handler. Shouldn't view on a phone.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Replies: 2
    Last Post: 03-16-2016, 09:55 AM
  2. Replies: 15
    Last Post: 11-20-2013, 04:30 PM
  3. Several fields vs multi-select list vs other?
    By DarthZ in forum Database Design
    Replies: 1
    Last Post: 02-15-2012, 10:28 AM
  4. Replies: 1
    Last Post: 03-01-2009, 09:53 AM
  5. Replies: 1
    Last Post: 02-25-2009, 07:29 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