View Full Version : Print one of two reports based on field value


kcolbert01
07-09-2004, 04:33 PM
I have a form that has all of the job descriptions in my company. Each job code has anywhere from 5 - 20 tasks which causes a problem when formatting in the report because there is too much space when there aren't a lot of tasks for the particular job code. So I have created 2 reports - one with the amount of tasks being under 12 and the other has all job codes with more than 12 tasks. Still with me??

Ok I have a field in the job description table called "LongJD" - it's a Y/N field that lets me know if the tasks are more than 12. So in my form I have this code on the print button:


Dim strReportName As String
Dim strWhere As String
If Me.LongJD = -1 Then
strReportName = "RptJobDesc_Main_Acct>12"
strWhere = "[JobCode]=" & JobCode
DoCmd.RunCommand acCmdSaveRecord
DoCmd.OpenReport strReportName, acPreview, , strWhere
Else


strReportName = "RptJobDesc_Main_Acct<12"
strWhere = "[JobCode]=" & JobCode
DoCmd.RunCommand acCmdSaveRecord
DoCmd.OpenReport strReportName, acPreview, , strWhere
End If
I get a "Enter the parameter value" and the job code i am trying to print is right under the message - like it's not reading the Job Code. I even enter the job code to see if that will work but it doesn't. Can anyone tell me what I am doing wrong? I'm so close....

Thanks in advance!

RichO
07-09-2004, 10:11 PM
I'm not saying that this is your problem but your code is a bit redundant. These 2 lines will accomplish the same conditional report opening:

DoCmd.RunCommand acCmdSaveRecord
DoCmd.OpenReport "RptJobDesc_Main_Acct" & Chr$(60 + Me.LongJD * -2) & "12", acPreview, , "[JobCode] = " & Me.JobCode


Chr$(60 + Me.LongJD * -2) will result in "<" or ">" depending on the value of LongJD.

Try referring to Me.JobCode as in the code above. See if that helps.