open report based on value

antonyx

Arsenal Supporter
Local time
Today, 20:27
Joined
Jan 7, 2005
Messages
556
Code:
Private Sub btnPreviewReport_Click()
On Error GoTo Err_btnPreviewReport_Click

    Dim stDocName As String

    stDocName = "rptInvoice"
    DoCmd.OpenReport stDocName, acPreview

Exit_btnPreviewReport_Click:
    Exit Sub

Err_btnPreviewReport_Click:
    MsgBox Err.Description
    Resume Exit_btnPreviewReport_Click
    
End Sub

i want to change this code which is currently on my form...

i want to open a specific report based on the first three letters of a control called txtInvoiceRef

so something like this perhaps??

Code:
Private Sub btnPreviewReport_Click()
On Error GoTo Err_btnPreviewReport_Click

    
    [b]If txtInvoiceRef (first 3) = MCD Then

    DoCmd.OpenReport rptMCD (report name), acPreview

    ElseIf 
 
    txtInvoiceRef (first 3) = BBC Then

    DoCmd.OpenReport rptBBC (report name), acPreview

    End if[/b]

Exit_btnPreviewReport_Click:
    Exit Sub

Err_btnPreviewReport_Click:
    MsgBox Err.Description
    Resume Exit_btnPreviewReport_Click
    
End Sub

i know its a poor attempt.. but this is the jist of what i am trying to do..

thanks.
 
Try something like this

Code:
Private Sub btnPreviewReport_Click()
On Error GoTo Err_btnPreviewReport_Click

    
    If txtInvoiceRef  like "MCD*" Then

    DoCmd.OpenReport rptMCD (report name), acPreview

    ElseIf 
 
    txtInvoiceRef like "BBC*" Then

    DoCmd.OpenReport rptBBC (report name), acPreview

    End if

Exit_btnPreviewReport_Click:
    Exit Sub

Err_btnPreviewReport_Click:
    MsgBox Err.Description
    Resume Exit_btnPreviewReport_Click
    
End Sub

HTH
 
yeah i got it working with this... thanks.

Code:
Private Sub btnPreviewReport_Click()
On Error GoTo Err_btnPreviewReport_Click

    
    If txtInvoiceRef Like "Q8A*" Then
    DoCmd.OpenReport "rptQ8Invoice", acPreview
    ElseIf txtInvoiceRef Like "KYP*" Then
    DoCmd.OpenReport "rptKYPInvoice", acPreview
    End If

Exit_btnPreviewReport_Click:
    Exit Sub

Err_btnPreviewReport_Click:
    MsgBox Err.Description
    Resume Exit_btnPreviewReport_Click
    
End Sub
 
Thanks for letting me know it worked!
 

Users who are viewing this thread

Back
Top Bottom