Results 1 to 2 of 2
  1. #1
    finsmith is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Dec 2012
    Posts
    27

    Update: Listbox to a query, i am able to print to a report

    HELLO ALL

    I am now rephrasing my work from a dropdown box, combo box into a list box, multi selection.
    I am trying to again push to a query, I have some samle code which works, but it goes into a table.
    Is there anyone that can help me modify the query button so it pushes it into a query.
    I appreciate your assistance.
    1MultiSelect1.mdb

  2. #2
    finsmith is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Dec 2012
    Posts
    27
    making lives easier,. here is the code


    Option Compare Database
    Option Explicit


    Private Sub cmdOpenReport_Click()
    On Error GoTo Err_cmdOpenReport_Click


    Dim strWhere As String
    Dim ctl As Control
    Dim varItem As Variant


    'make sure a selection has been made
    If Me.lstEmployees.ItemsSelected.Count = 0 Then
    MsgBox "Must select at least 1 employee"
    Exit Sub
    End If


    'add selected values to string
    Set ctl = Me.lstEmployees
    For Each varItem In ctl.ItemsSelected
    strWhere = strWhere & ctl.ItemData(varItem) & ","
    Next varItem
    'trim trailing comma
    strWhere = Left(strWhere, Len(strWhere) - 1)
    'open the report, restricted to the selected items
    DoCmd.OpenReport "rptEmployees", acPreview, , "EmpID IN(" & strWhere & ")"


    Exit_cmdOpenReport_Click:
    Exit Sub


    Err_cmdOpenReport_Click:
    MsgBox Err.Description
    Resume Exit_cmdOpenReport_Click


    End Sub
    Private Sub Command4_Click()
    On Error GoTo Err_Command4_Click


    Dim stDocName As String


    stDocName = "rptEmployees"
    DoCmd.OpenReport stDocName, acViewReport


    Exit_Command4_Click:
    Exit Sub


    Err_Command4_Click:
    MsgBox Err.Description
    Resume Exit_Command4_Click

    End Sub


    Private Sub Command5_Click()
    On Error GoTo Err_Command5_Click


    'Dim stDocName As String


    'stDocName = "qryAllEmployees"
    'DoCmd.OpenQuery stDocName, acNormal, acEdit


    Dim strWhere As String
    Dim ctl As Control
    Dim varItem As Variant


    'make sure a selection has been made
    If Me.lstEmployees.ItemsSelected.Count = 0 Then
    MsgBox "Must select at least 1 employee"
    Exit Sub
    End If


    'add selected values to string
    Set ctl = Me.lstEmployees
    For Each varItem In ctl.ItemsSelected
    strWhere = strWhere & ctl.ItemData(varItem)
    '& ","
    Next varItem
    'trim trailing comma
    strWhere = Left(strWhere, Len(strWhere) - 1)
    'open the report, restricted to the selected items
    ' DoCmd.OpenQuery strWhere, acNormal, acEdit
    DoCmd.OpenQuery "qryAllEmployees" acPreview, , "EmpID IN(" & strWhere & ")"



    Exit_Command5_Click:
    Exit Sub

    i just need help to do the query print.

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

Similar Threads

  1. Requery Does Not Update Listbox Row Source
    By szucker1 in forum Forms
    Replies: 7
    Last Post: 02-11-2014, 08:58 AM
  2. Replies: 1
    Last Post: 12-03-2012, 03:15 PM
  3. Listbox update
    By Pgill in forum Forms
    Replies: 4
    Last Post: 07-25-2011, 11:42 AM
  4. Replies: 0
    Last Post: 02-22-2011, 05:04 AM
  5. Replies: 3
    Last Post: 04-14-2010, 10:00 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