Solved Multi select_report (1 Viewer)

kavehrad

New member
Local time
Today, 19:30
Joined
Jun 14, 2020
Messages
17
Hi!
I have a form with a listbox from a table. I want to get report from this with 1 ro more records. but its doesn´t work. when I change listbox to combobox so I have report without problem but it gives me just 1 record in the report and i want to have more than 1 record. can anyone help me to solve the problem? Attached my DB
Thanks/Kaveh
 

Attachments

  • Tunet.accdb
    2.6 MB · Views: 84

Gasman

Enthusiastic Amateur
Local time
Today, 18:30
Joined
Sep 21, 2011
Messages
14,309
This is how I did it in one of my DBs

HTH
Code:
Private Sub cmdReport_Click()
On Error GoTo Err_Handler
'Dim db As DAO.Database
'Dim qdf As DAO.QueryDef
Dim ctl As Control
Dim varItem As Variant
Dim strParam As String, strRptQuery As String

'First validate we have all the data we need
If IsNull(Me.cboEmployeeID) Then
    MsgBox ("Employee is mandatory")
    Me.cboEmployeeID.SetFocus
    Exit Sub
End If
If IsNull(Me.txtStartdate) Then
    MsgBox ("Start date is mandatory")
    Exit Sub
End If
If IsNull(Me.txtEnddate) Then
    MsgBox ("End date is mandatory")
    Exit Sub
End If
   
strRptQuery = "qryEmployeeHours"
Set ctl = Me!lstDayType
'Open the report with an OpenArgs value to get selected hours for employee
' Now select what type of day records from listbox
If ctl.ItemsSelected.Count > 0 Then
    For Each varItem In ctl.ItemsSelected
        strParam = strParam & ctl.ItemData(varItem) & ","
    Next varItem
  Else
    MsgBox ("At least one Day Type is required")
    Exit Sub
End If

' Need to pass the criteria as a string
strParam = " IN (" & Left(strParam, Len(strParam) - 1) & ")"
'Debug.Print strParam
'Set db = CurrentDb
'Set qdf = db.QueryDefs(strRptQuery)
'qdf.Parameters("pInList") = strParam
'qdf.Close

strParam = "[DateType]" & strParam
DoCmd.OpenReport "rptHours", acViewReport, , strParam, , "Selected"
'docmd.OpenReport "tt",acViewPreview,,"[DateType]=15",,,

Exit_Sub:
    Set ctl = Nothing
    'Set db = Nothing
    'Set qdf = Nothing

Err_Exit:
    Exit Sub
    
Err_Handler:
    MsgBox "Error " & Err.Number & " " & Err.Description
    Resume Exit_Sub
End Sub
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 01:30
Joined
May 7, 2009
Messages
19,245
add an Unbound textbox and use the Unbound textbox on your Query.
see the code behind the listbox1 AfterUpdate.
 

Attachments

  • Tunet.zip
    36.4 KB · Views: 92

kavehrad

New member
Local time
Today, 19:30
Joined
Jun 14, 2020
Messages
17
This is how I did it in one of my DBs

HTH
Code:
Private Sub cmdReport_Click()
On Error GoTo Err_Handler
'Dim db As DAO.Database
'Dim qdf As DAO.QueryDef
Dim ctl As Control
Dim varItem As Variant
Dim strParam As String, strRptQuery As String

'First validate we have all the data we need
If IsNull(Me.cboEmployeeID) Then
    MsgBox ("Employee is mandatory")
    Me.cboEmployeeID.SetFocus
    Exit Sub
End If
If IsNull(Me.txtStartdate) Then
    MsgBox ("Start date is mandatory")
    Exit Sub
End If
If IsNull(Me.txtEnddate) Then
    MsgBox ("End date is mandatory")
    Exit Sub
End If
  
strRptQuery = "qryEmployeeHours"
Set ctl = Me!lstDayType
'Open the report with an OpenArgs value to get selected hours for employee
' Now select what type of day records from listbox
If ctl.ItemsSelected.Count > 0 Then
    For Each varItem In ctl.ItemsSelected
        strParam = strParam & ctl.ItemData(varItem) & ","
    Next varItem
  Else
    MsgBox ("At least one Day Type is required")
    Exit Sub
End If

' Need to pass the criteria as a string
strParam = " IN (" & Left(strParam, Len(strParam) - 1) & ")"
'Debug.Print strParam
'Set db = CurrentDb
'Set qdf = db.QueryDefs(strRptQuery)
'qdf.Parameters("pInList") = strParam
'qdf.Close

strParam = "[DateType]" & strParam
DoCmd.OpenReport "rptHours", acViewReport, , strParam, , "Selected"
'docmd.OpenReport "tt",acViewPreview,,"[DateType]=15",,,

Exit_Sub:
    Set ctl = Nothing
    'Set db = Nothing
    'Set qdf = Nothing

Err_Exit:
    Exit Sub
   
Err_Handler:
    MsgBox "Error " & Err.Number & " " & Err.Description
    Resume Exit_Sub
End Sub
Thank you for your reply but I am a beginner and don´t understand how to use this :(
 

bob fitz

AWF VIP
Local time
Today, 18:30
Joined
May 23, 2011
Messages
4,727
kavehrad

Try attached db
 

Attachments

  • TunetBob01.zip
    41.2 KB · Views: 89

bob fitz

AWF VIP
Local time
Today, 18:30
Joined
May 23, 2011
Messages
4,727
kavehrad

As far as I can see the db's provided by arnelgp and myself use different methods to achieve the same result.

Please explain how your requirements differ from the examples given.
 

kavehrad

New member
Local time
Today, 19:30
Joined
Jun 14, 2020
Messages
17
kavehrad

As far as I can see the db's provided by arnelgp and myself use different methods to achieve the same result.

Please explain how your requirements differ from the examples given.
I've downloaded both yours and his attached DB but none of them work.
I want to select 2 or more records on the list box and see reports on records that I have selected. I select my records and press ÖPPNA but nothing happens
 

bob fitz

AWF VIP
Local time
Today, 18:30
Joined
May 23, 2011
Messages
4,727
When you open the db do you get a yellow band below the ribbon with a button which says Enable Content on it. If you do you will need to click it.
 

Users who are viewing this thread

Top Bottom