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

report question

100+
P: 243
i have a form that filters results based on an entry in an unbound text box, i then have a button that creates a report from those filtered results, using this code

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command8_Click()
  2.   If Me.Filter = "" Then
  3.         MsgBox "Apply a filter to the form first."
  4.     Else
  5.         DoCmd.OpenReport "Id", acViewPreview, , Me.Filter
  6.     End If
is there a way to put a heading on the report by entering it into an unbound text box in the form. so if im making an attendance report, i would like to enter 'attendance' in an unbound text box after i do my filter and then create my report and 'attendance' would be on the top of the report... thanks!
Jan 12 '10 #1
Share this Question
Share on Google+
7 Replies


nico5038
Expert 2.5K+
P: 3,072
For this I use a "Header/Footer" table with the name of the report as (part of) the key.
Thus each report can have a different header/footer and by storing it the user can always see the last entered value. (easy when multiple reports with same header should be produced.)

Idea ?

Nic;o)
Jan 12 '10 #2

TheSmileyCoder
Expert Mod 100+
P: 2,321
Add a label to your report in the report Header section, and name it lbl_ReportTitle. Format it as you would like to see the report title, and make sure its wide enough to contain what people might write as a report title.
If your report header section is not visible, you can add it by clicking on the detail section, and then selecting Report Header/Footer.

Now add the following code to the Reports open event

Expand|Select|Wrap|Line Numbers
  1. Private Sub Report_Open(Cancel as Integer)
  2.   me.lbl_ReportTitle=OpenArgs & ""
  3. End Sub
The "" after the OpenArgs assures that if OpenArgs is null the code wont fail.

Add a textbox to your form, name it tb_ReportTitle.
Modify the code line of the command button to:
Expand|Select|Wrap|Line Numbers
  1. DoCmd.OpenReport "Id", acViewPreview, , Me.Filter ,, Me.tb_ReportTitle & ""
Another way of doing it without the textbox is to use a inputbox:
Expand|Select|Wrap|Line Numbers
  1. Dim strOpenArgs As String
  2. strOpenArgs=InputBox("Name Report:","Report Title","Report Title")
  3. DoCmd.OpenReport "Id", acViewPreview, , Me.Filter ,, strOpenArgs
Hope it helps.
Jan 12 '10 #3

100+
P: 243
i actually came up with this earlier...

Expand|Select|Wrap|Line Numbers
  1. Me.rpttxt = Forms!FormName!FormField
it works well... any thoughts id be glad to hear... thanks for your answers though!
Jan 12 '10 #4

nico5038
Expert 2.5K+
P: 3,072
I prefer not to refer to forms as a change of the form name or starting a report from a different form will cause "trouble".
The mentioned "OpenArgs" is preferable for "ad-hoc" passing of data and can be used "universally" as the table solution is "heavier" and would offer the user the advantage to have his(her) own text for a header or footer per report, thus saving you the trouble to add default texts like copyright, address info, etc..

Nic;o)
Jan 12 '10 #5

100+
P: 243
when i try it the way suggested, i get an error. "you cannot assign a value to this object" with the following highlighted

me.lbl_ReportTitle=OpenArgs & ""
Jan 13 '10 #6

TheSmileyCoder
Expert Mod 100+
P: 2,321
My bad. Labels have a Caption not a value, so you need to include the .Caption to assign to labels.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Report_Open(Cancel as Integer) 
  2.   me.lbl_ReportTitle.Caption=OpenArgs & "" 
  3. End Sub
Jan 13 '10 #7

100+
P: 243
yep there it goes... awesome! thanks for your help!
Jan 13 '10 #8

Post your reply

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