Print conditionally

naungsai

Abecedarian
Local time
Today, 07:10
Joined
Sep 8, 2008
Messages
123
Dear Friends

I am buiding a form to print cheques. In my office, we use 2 currency; USDollar and MMK(Local Currency). Because the size of the 2 cheques are different, I have created 2 reports. In my form, I also have a field for these2 currency.

In clicking the Print button, the print preview of the cheque will be display the MMKCheque or USDCheque depend on the value in the currency. I have filtered the record to be the current one. The following code is the one I have try.

thanks for your help in advanced.:)

Code:
Private Sub PrintCheque_Click()
On Error GoTo Err_cmdPrintLabel_Click
    
Dim Cheque As String
Dim Currencys As String
If Currencys = "MMK" Then
        Cheque = "MMKCheques"
    Else
        Cheque = "USDCheques"
End If
DoCmd.OpenReport Cheque, acPreview, , "[ID] like '" & Me![ID] & "'"
    
Exit_cmdPrintLabel_Click:
    Exit Sub
    
Err_cmdPrintLabel_Click:
        MsgBox Err.Description
        Resume Exit_cmdPrintLabel_Click
End Sub
 
You haven't even told us what the problem is (if any). Are you getting an error message? something else? It could be that your [ID] field is numeric and you are wrapping it with string delimiters, but I'm just spit balling since you haven't provided enough info to analyze the problem.
 
The problem is, it does not choose the correct "Cheque" type depend on "Currencys". It keeps on printing using the "USDChues" when I want it to print in "MMKCheques". This is the question number 1, I want to solve.

Another question is, how do I create a report field not to be printed via printer but display in "Print Preview".


Thanks in advance.:)
 
You have Dim'ed the variable Currencys BUT you have NOT set it to anything so it will always be an empty string and your IF statement will only execute the Else-part and open the report "USDCheques".

Code:
Private Sub PrintCheque_Click()
On Error GoTo Err_cmdPrintLabel_Click
    
Dim Cheque As String
Dim Currencys As String
 
[COLOR=red]Currencys = ????? <- Perhaps a poniter to a formcontrol?[/COLOR]
 
If Currencys = "MMK" Then
        Cheque = "MMKCheques"
    Else
        Cheque = "USDCheques"
End If
DoCmd.OpenReport Cheque, acPreview, , "[ID] like '" & Me![ID] & "'"
    
Exit_cmdPrintLabel_Click:
    Exit Sub
    
Err_cmdPrintLabel_Click:
        MsgBox Err.Description
        Resume Exit_cmdPrintLabel_Click
End Sub
 

Users who are viewing this thread

Back
Top Bottom