Solved Print selected invoice (1 Viewer)

Mercy Mercy

Member
Local time
Today, 18:32
Joined
Jan 27, 2023
Messages
87
Hello everyone. I have a slight problem. The following code does not fire to print selected records in invoice. It is supposed to filter the selected records and the studentID

Code:
Private Sub Command48_Click()
Dim sFilter As String
On Error Resume NextDoCmd.CLOSE acReport, "INVOICE"
sFilter = Me.SelectedList & ""If Len(sFilter) <> 0 Then    Do While Right$(sFilter, 1) = ","        sFilter = Left$(sFilter, Len(sFilter) - 1)    Loop    Do While Left$(sFilter, 1) = ","        sFilter = Mid$(sFilter, 2)    Loop    DoCmd.OpenReport "INVOICE", acViewPreview, , "StudentID IN (" & sFilter & ")"Else    DoCmd.OpenReport "INVOICE", acViewPreviewEnd IfEnd Sub


I have attached an image to show the selected records.
Thanks in advance
 

Attachments

  • page01.jpg
    page01.jpg
    629.7 KB · Views: 80
Last edited:

Gasman

Enthusiastic Amateur
Local time
Today, 16:32
Joined
Sep 21, 2011
Messages
14,306
Don't try and be clever.
Break it down to logical steps.

Then use Debug.Print to see what sFilter actually is, not what you think it is.

ALso try and give your controls meaningful names. Command48 is not going to mean much to anyone 6 months down the line.
 

ebs17

Well-known member
Local time
Today, 17:32
Joined
Feb 7, 2020
Messages
1,946
The following code does not fire
Of course, the code is also full of errors.
Throw out these mistakes or start over.
 

Mercy Mercy

Member
Local time
Today, 18:32
Joined
Jan 27, 2023
Messages
87
Don't try and be clever.
Break it down to logical steps.

Then use Debug.Print to see what sFilter actually is, not what you think it is.

ALso try and give your controls meaningful names. Command48 is not going to mean much to anyone 6 months down the line.
Enthusiastic amateur I like your name but you have not assisted in anyway.
 

Mercy Mercy

Member
Local time
Today, 18:32
Joined
Jan 27, 2023
Messages
87
Don't try and be clever.
Break it down to logical steps.

Then use Debug.Print to see what sFilter actually is, not what you think it is.

ALso try and give your controls meaningful names. Command48 is not going to mean much to anyone 6 months down the line.
I thought it is common sense Command48 is PRINT SELECTED INVOICE as the title and the image attached?????
 

ebs17

Well-known member
Local time
Today, 17:32
Joined
Feb 7, 2020
Messages
1,946
First Step:
On Error Resume Next|DoCmd.CLOSE acReport, "INVOICE"

That's TWO statements, so it should be TWO lines of code.
Change that, same stuff below just like that.
Then you present the changed code again.

Additionally: If you simply start a procedure with "On Error Resume Next", you want to ignore errors, not fix them. Something like that deserves a (symbolic) headbutt.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 23:32
Joined
May 7, 2009
Messages
19,245
we dont know what is SelectedList but you may try:
Code:
Private Sub Command48_Click()
    Dim sFilter As String
    On Error Resume Next
    DoCmd.Close acReport, "INVOICE"
    On Error GoTo err_handler
    sFilter = Trim$(Me.SelectedList & "")
    If Right$(sFilter, 1) = "," Then
        sFilter = Left$(sFilter, Len(sFilter) - 1)
    End If
    If Left$(sFilter, 1) = "," Then
        sFilter = Mid$(sFilter, 2)
    End If
    If Len(sFilter) <> 0 Then
        DoCmd.OpenReport "INVOICE", acViewPreview, , "StudentID IN (" & sFilter & ")"
    Else
        DoCmd.OpenReport "INVOICE", acViewPreview
    End If
exit_sub:
    Exit Sub
err_handler:
    MsgBox Err.Number & ": " & Err.Description
    Resume exit_sub
End Sub
 

Mercy Mercy

Member
Local time
Today, 18:32
Joined
Jan 27, 2023
Messages
87
we dont know what is SelectedList but you may try:
Code:
Private Sub Command48_Click()
    Dim sFilter As String
    On Error Resume Next
    DoCmd.Close acReport, "INVOICE"
    On Error GoTo err_handler
    sFilter = Trim$(Me.SelectedList & "")
    If Right$(sFilter, 1) = "," Then
        sFilter = Left$(sFilter, Len(sFilter) - 1)
    End If
    If Left$(sFilter, 1) = "," Then
        sFilter = Mid$(sFilter, 2)
    End If
    If Len(sFilter) <> 0 Then
        DoCmd.OpenReport "INVOICE", acViewPreview, , "StudentID IN (" & sFilter & ")"
    Else
        DoCmd.OpenReport "INVOICE", acViewPreview
    End If
exit_sub:
    Exit Sub
err_handler:
    MsgBox Err.Number & ": " & Err.Description
    Resume exit_sub
End Sub
Error 3075: Invalid use of vertical bars in query expression 'StudentID IN (11|)'.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 23:32
Joined
May 7, 2009
Messages
19,245
your delimiter is vertical bar? try more:
Code:
Private Sub Command48_Click()
    Dim sFilter As String
    On Error Resume Next
    DoCmd.Close acReport, "INVOICE"
    On Error GoTo err_handler
    sFilter = Trim$(Replace$(Me.SelectedList & "", "|", ","))
    If Right$(sFilter, 1) = "," Then
        sFilter = Left$(sFilter, Len(sFilter) - 1)
    End If
    If Left$(sFilter, 1) = "," Then
        sFilter = Mid$(sFilter, 2)
    End If
    If Len(sFilter) <> 0 Then
        DoCmd.OpenReport "INVOICE", acViewPreview, , "StudentID IN (" & sFilter & ")"
    Else
        DoCmd.OpenReport "INVOICE", acViewPreview
    End If
exit_sub:
    Exit Sub
err_handler:
    MsgBox Err.Number & ": " & Err.Description
    Resume exit_sub
End Sub
 

Mercy Mercy

Member
Local time
Today, 18:32
Joined
Jan 27, 2023
Messages
87
your delimiter is vertical bar? try more:
Code:
Private Sub Command48_Click()
    Dim sFilter As String
    On Error Resume Next
    DoCmd.Close acReport, "INVOICE"
    On Error GoTo err_handler
    sFilter = Trim$(Replace$(Me.SelectedList & "", "|", ","))
    If Right$(sFilter, 1) = "," Then
        sFilter = Left$(sFilter, Len(sFilter) - 1)
    End If
    If Left$(sFilter, 1) = "," Then
        sFilter = Mid$(sFilter, 2)
    End If
    If Len(sFilter) <> 0 Then
        DoCmd.OpenReport "INVOICE", acViewPreview, , "StudentID IN (" & sFilter & ")"
    Else
        DoCmd.OpenReport "INVOICE", acViewPreview
    End If
exit_sub:
    Exit Sub
err_handler:
    MsgBox Err.Number & ": " & Err.Description
    Resume exit_sub
End Sub
It provides print preview for a different student
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 23:32
Joined
May 7, 2009
Messages
19,245
then the filter you have is coming from wrong Table.
i don't see any student in your snapshot on #1.
 

Users who are viewing this thread

Top Bottom