OpenReport through code instead of a macro

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • geomfg
    New Member
    • Aug 2008
    • 3

    OpenReport through code instead of a macro

    Since I'm new I like using macro's over code, but coding allows me to do so much more. I'm still learning.

    I have a macro for a button that opens a report with a long "Where Condition" I understand that the macro does not support as many characters as code does in the "where condition"

    Heres an example of what I'm trying to do with the Macro (as one line without returns)

    ([ReceiveType] Like [Forms]![MakeReport]![Combo27]) And
    ([CompanyName] Like [Forms]![MakeReport]![Combo29]) And
    ([DateReceived] Like [Forms]![MakeReport]![Combo37]) And
    ([ReceiveRef] Like [Forms]![MakeReport]![Combo33]) And
    ([NewService] Like [Forms]![MakeReport]![Combo43]) And
    ([BoardType] Like [Forms]![MakeReport]![Combo31])

    Can someone help me with this code?

    All help is appreciated. Thanks
  • hyperpau
    Recognized Expert New Member
    • Jun 2007
    • 184

    #2
    Apply this code on the On-Click event of your button.

    [CODE=VB]Private Sub cmdYourButton_C lick()
    Dim stCriteria as String

    stCriteria = "[ReceiveType] ='" & Me![Combo27] & "' And [CompanyName] ='" & Me![Combo29] & _
    "' And [DateReceived] ='" & Me![Combo37] & "' And [ReceiveRef] ='" & Me![Combo33] & _
    "' And [NewService] ='" & Me![Combo43] & "' And [BoardType] = '" & Me![Combo31] & "'"

    DoCmd.OpenRepor t "rptYourReport" , acPreview, , stCriteria , acDialog
    End Sub[/CODE]


    Note: This should work assuming all of your comboboxes are bound to a String field. If some of them are Numbers, you need to omit the singlequotes (').

    Ex:
    Code:
    "[ReceiveType] =" & Me![Combo27] & "And ......
    Instead of
    Code:
    "[ReceiveType] ='" & Me![Combo27] & "' And ......
    Originally posted by geomfg
    Since I'm new I like using macro's over code, but coding allows me to do so much more. I'm still learning.

    I have a macro for a button that opens a report with a long "Where Condition" I understand that the macro does not support as many characters as code does in the "where condition"

    Heres an example of what I'm trying to do with the Macro (as one line without returns)

    ([ReceiveType] Like [Forms]![MakeReport]![Combo27]) And
    ([CompanyName] Like [Forms]![MakeReport]![Combo29]) And
    ([DateReceived] Like [Forms]![MakeReport]![Combo37]) And
    ([ReceiveRef] Like [Forms]![MakeReport]![Combo33]) And
    ([NewService] Like [Forms]![MakeReport]![Combo43]) And
    ([BoardType] Like [Forms]![MakeReport]![Combo31])

    Can someone help me with this code?

    All help is appreciated. Thanks

    Comment

    Working...