By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,476 Members | 889 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,476 IT Pros & Developers. It's quick & easy.

OpenReport through code instead of a macro

P: 3
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
Aug 22 '08 #1
Share this Question
Share on Google+
1 Reply


hyperpau
Expert 100+
P: 184
Apply this code on the On-Click event of your button.

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdYourButton_Click()
  2. Dim stCriteria as String
  3.  
  4. stCriteria = "[ReceiveType] ='" & Me![Combo27] & "' And [CompanyName] ='" & Me![Combo29] & _
  5. "' And [DateReceived] ='" & Me![Combo37] & "' And [ReceiveRef] ='" &  Me![Combo33] & _
  6. "' And [NewService] ='" & Me![Combo43] & "' And [BoardType] = '" & Me![Combo31] & "'"
  7.  
  8. DoCmd.OpenReport "rptYourReport", acPreview, ,  stCriteria , acDialog 
  9. End Sub

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:
Expand|Select|Wrap|Line Numbers
  1. "[ReceiveType] =" & Me![Combo27] & "And ......
Instead of
Expand|Select|Wrap|Line Numbers
  1. "[ReceiveType] ='" & Me![Combo27] & "' And ......
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
Aug 22 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.