Open different reports depending on a field. (1 Viewer)

Ivandlouhy

New member
Local time
Today, 09:03
Joined
Jul 14, 2022
Messages
4
Hi all!
I need your help to write a code for a button (on click). I need to open reports from a record list, but depending on the field lymphomatype I need different reports. So if lymphomatype is 1, I need to use report1, if lymphomatype is 2, report2, and so on.
Any ideas?
Thanks in advance

Ivan
 

MarkK

bit cruncher
Local time
Today, 02:03
Joined
Mar 17, 2004
Messages
8,178
Hey Ivan:
What have you tried? Where are you stuck? The question you are posing is so broad as to be almost unanswerable. Maybe you can narrow it down a bit so you get useful responses.
Cheers,
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 05:03
Joined
May 21, 2018
Messages
8,463
You can post a sample database which is usually the best way to show the issue. Or some screen shots help too.
 

Gasman

Enthusiastic Amateur
Local time
Today, 09:03
Joined
Sep 21, 2011
Messages
14,037
So append the value of lymphomatype to "Report"
Alternatively have a table that matches value of lymphomatype with correct report in case they are named more like "Balance due", "Vacant positions" etc.
 

Ivandlouhy

New member
Local time
Today, 09:03
Joined
Jul 14, 2022
Messages
4
Hey Ivan:
What have you tried? Where are you stuck? The question you are posing is so broad as to be almost unanswerable. Maybe you can narrow it down a bit so you get useful responses.
Cheers,
Hi MarkK, thanks for the replay.

I have tried an if else funcion:

Private Sub PrintCDTBtn_Click()
If Tipolinfoma = "1" Then
DoCmd.OpenReport "DLBCLReport", acViewPreview
Else: DoCmd.OpenReport "LFReport", acViewPreview
End If
End Sub
--> this opens just LFReport for all records.

I have tried also:

Dim strReport As String
Dim strCriteria As String
If Me.Tipolinfoma = "1" Then
strReport = "DLBCLReport"
Else
strReport = "LFReport"
End If
DoCmd.OpenReport strReport, View:=acViewPreview, WhereCondition:=strCriteria

same result.

any suggestion?
thanx
 

Gasman

Enthusiastic Amateur
Local time
Today, 09:03
Joined
Sep 21, 2011
Messages
14,037
Is Tipolinfoma a string?
Walk through your code line by line with F8, and inspect the variables
You are not even setting strCriteria ? :(
 

Ivandlouhy

New member
Local time
Today, 09:03
Joined
Jul 14, 2022
Messages
4
Hi, thanks for the replies.
here is the file.
tipolinfoma is a number variable.
what I need is from the form "CDTList_Print", that the "Print report para CDT" button opens the report for the records. I have 2 types of reports: DLBCLReport and LFReport. I need to open DLBCLReport when tipolinfoma is 1, and LFReport when tipolinfoma is 2.
Thank you
 

Attachments

  • for forum.accdb
    1.3 MB · Views: 80

Gasman

Enthusiastic Amateur
Local time
Today, 09:03
Joined
Sep 21, 2011
Messages
14,037
Well if it as number do not surround it with " ", that is for text.
I cannot amend your DB, my access is too old. Just remove the quotes around 1 and try that.
 

Ivandlouhy

New member
Local time
Today, 09:03
Joined
Jul 14, 2022
Messages
4
Well if it as number do not surround it with " ", that is for text.
I cannot amend your DB, my access is too old. Just remove the quotes around 1 and try that.
Thanks, but still continues to use the same report form for all cases
 

Gasman

Enthusiastic Amateur
Local time
Today, 09:03
Joined
Sep 21, 2011
Messages
14,037
Walk through your code and inspect the values.
 

MarkK

bit cruncher
Local time
Today, 02:03
Joined
Mar 17, 2004
Messages
8,178
Using the database you posted, the code works correctly on my machine. For carlos and juan the LFReport opens. For the other two it is the other report.
 

Users who are viewing this thread

Top Bottom