Filter and print the current record in the form in the report

Anonymous
2023-01-10T10:07:25.847+00:00

Hello,

I would like to insert a button in my form with which you can filter a report according to the current record in the form and print it directly. Below is my current code, but something seems to be wrong because he prints all records.

I hope someone has an idea, thanks Caro

Private Sub Befehl4982_Click()
Dim DocName As String
Dim strFltr As String
DocName = "Ber_Checkliste_Angebot"
strFltr = "[Angebotsnummer]=Forms![Checkliste Angebot]![Angebotsnummer]"
DoCmd.OpenReport DocName, acNormal, , strFltr
End Sub
Access Development
Access Development
Access: A family of Microsoft relational database management systems designed for ease of use.Development: The process of researching, productizing, and refining new or existing technologies.
893 questions
0 comments No comments
{count} votes

4 answers

Sort by: Most helpful
  1. Karl Donaubauer 2,056 Reputation points MVP
    2023-01-10T15:46:44.76+00:00

    Hi,

    I see no real error in your syntax, although I would not write it like this. What data type does the field Angebotsnummer have?

    Have you checked the value of the criteria, using a break point or with

    Debug.Print Forms![Checkliste Angebot]![Angebotsnummer]

    and then have a look at the result in the Immediate Window?

    You could also try to formulate the filter differently. Maybe you'll get an error message because of data types or the like. Based on your object names, I assume you understand German. Then take a look at this syntax variant.

    Servus Karl

    Access Bug Trackers Access News Access DevCon

    0 comments No comments

  2. xps350 381 Reputation points
    2023-01-10T16:05:48.59+00:00

    I think the problem is the line: strFltr = "[Angebotsnummer]=Forms![Checkliste Angebot]![Angebotsnummer]"

    Depending on the type of the Angebotsnummer, try (numeric): strFltr = "[Angebotsnummer]=" & Forms![Checkliste Angebot]![Angebotsnummer] or strFltr = "[Angebotsnummer]='" & Forms![Checkliste Angebot]![Angebotsnummer] & "'"

    0 comments No comments

  3. Ken Sheridan 2,846 Reputation points
    2023-01-10T17:50:31.287+00:00

    One thing I'd add is that you ensure the current record is saved with:

    Me.Dirty = False
    

    before opening the report.

    0 comments No comments

  4. Anonymous
    2023-01-11T06:39:49.0833333+00:00

    Thank you very much, it works now. I have replaced this line with the following wording:

    DoCmd.OpenReport "Ber_Checkliste_Angebot", , , "Angebotsnummer = '" & Me!Angebotsnummer & "'"
    
    

    I also added the line to save the record, thanks for the hint.

    Thanks a lot, have a nice day.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.