UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> Print Report Based On Combo Result, Access 2016    
 
   
bigdano
post Aug 19 2019, 07:06 PM
Post#1



Posts: 33
Joined: 20-February 17



I am trying to find a way to print report A if combo box is select with A, else print report B if combo box is select with B, My attempt at writing this code is:

If (Combo251) = [A] Then
DoCmd.OpenReport "A", acViewPreview, , "[Nb] = '" & [Nb] & "'"
Else
If (Combo251) = [B] Then
DoCmd.OpenReport "B", acViewPreview, , "[Nb] = '" & [Nb] & "'"

End If
End If

Thank you for any help
Go to the top of the page
 
DanielPineault
post Aug 19 2019, 07:22 PM
Post#2


UtterAccess VIP
Posts: 6,848
Joined: 30-June 11



One option would be something like
CODE
    If IsNull(Me.Combo25) = False Then
        Select Case Me.Combo25
        Case "A"
            DoCmd.OpenReport "A", acViewPreview, , "[Nb] = '" & Me.Nb & "'"
        Case "B"
            DoCmd.OpenReport "B", acViewPreview, , "[Nb] = '" & Me.Nb & "'"
        End Select
    End If

Or perhaps you can simply do
CODE
    If IsNull(Me.Combo25) = False Then
        DoCmd.OpenReport Me.Combo25, acViewPreview, , "[Nb] = '" & Me.Nb & "'"
    End If



--------------------
Daniel Pineault (2010-2019 Microsoft MVP)
Professional Help: http://www.cardaconsultants.com
Free MS Access Code, Tips, Tricks and Samples: http://www.devhut.net

* Design should never say "Look at me". It should always say "Look at this". -- David Craib
* A user interface is like a joke, if you have to explain it, it's not that good! -- Martin LeBlanc


All code samples, demonstration databases, links,... are provided 'AS IS' and are to be used at your own risk! Take the necessary steps to check, validate ...(you are responsible for your choices and actions)
Go to the top of the page
 
RJD
post Aug 19 2019, 07:35 PM
Post#3


UtterAccess VIP
Posts: 10,023
Joined: 25-October 10
From: Gulf South USA


Hi: Daniel has good answers for you. But if you just want to clean up the code you started, you could do this ...

If (Combo251) = "A" Then
DoCmd.OpenReport "A", acViewPreview, , "[Nb] = '" & [Nb] & "'"
ElseIf (Combo251) = "B" Then
DoCmd.OpenReport "B", acViewPreview, , "[Nb] = '" & [Nb] & "'"
End If

You were pretty close, just adjust the =[A] to ="A" (and B as well), combine the Else and If rows, and eliminate one End If.

This assumes that [Nb] is text (a string) and is on the form that the module is a part of, and I would also add & Me!Nb & instead of just Nb.

That should do it ...

HTH
Joe

--------------------
"Each problem that I solved became a rule, which served afterwards to solve other problems."
"You just keep pushing. You just keep pushing. I made every mistake that could be made. But I just kept pushing."

Rene Descartes 1596-1650 (Mathematician and Philosopher)
Go to the top of the page
 
bigdano
post Aug 19 2019, 07:49 PM
Post#4



Posts: 33
Joined: 20-February 17



Thank you, it works great
Go to the top of the page
 


Custom Search


RSSSearch   Top   Lo-Fi    20th September 2019 - 11:56 AM