Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

passing Global variable values to a function & Report

Status
Not open for further replies.

CompAnalyst

Programmer
Nov 11, 2003
33
US
Ok... i am feeling like an idiot. I am a self taught Access VBA developer and I am trying to get a string value to be passed to a report. Basically the user makes a selection of which report he wants to run, and I want the proper title to populate in the Report. I thought the way to do this was first to create a global variable in the general section and depending on what the user selects, it sets that string. I can get it to do that, now the problem is getting into the report. When i use a public function to basically get the info into the report it prompts me for the value of the function (aka a Parameter Value).

This is the code i had been working with:

Public Function fReportTitle() as String
fReportTitle= gReportTitle
End Function

then i set the control source of the text box in the report to =fReportTitle()
Argh what am i doing wrong?????
 
That will happen if gReportTitle does not have a value. Where are you defining gReportTitle?
 
its defined in the General section. yes/no? so i define all my global variables in the general section of the form... or am i supposed to put it somewhere else?
 
When you say proper title, what do you mean? Do you mean the title bar of the report?

If so, all you need it in the OnOpen event of the Report:

Me.Caption = Forms![formname]![fieldname]

If you want a particular field in the report to be something, make sure it is unbound and do the same:

Me![fieldname] = Forms![formname]![fieldname]

****************************
People think it must be fun to be a super genius, but they don't realize how hard it is to put up with all the idiots in the world. (Calvin from Calvin And Hobbs)

Robert L. Johnson III
MCSA, CNA, Net+, A+
w: rljohnso@stewart.com
h: wildmage@tampabay.rr.com
 
its more like the user is selecting a radio button which says "1st Quarter", "2nd Quarter" etc etc etc. and in the code i define the string for the report title as "1st Quarter 2003" etc. so... i think i have the variable set up correctly, i just cant get the info to get into the report field. I can't use the code u just supplied (thank you) becuase there is no field that the user is filling in... just selecting a quarter.
 
Ahhhhh....arethe radio buttons memebrs of an Option Group??? If so, you can get the VALUE of the option group and evaluate that in the Report for the correct title....

****************************
People think it must be fun to be a super genius, but they don't realize how hard it is to put up with all the idiots in the world. (Calvin from Calvin And Hobbs)

Robert L. Johnson III
MCSA, CNA, Net+, A+
w: rljohnso@stewart.com
h: wildmage@tampabay.rr.com
 
Okay....you can do basically what I proposed above....

In the OnOpen Event of the Report:

Select Case Forms![formname]![optiongroupname]
Case 1: Me.Caption = "Whatever"
Case 2: Me.Caption = "You Want"
Case 3: Me.Caption = "These To Say"
End Select

Just change the formname and optiongroupname to whatever you have, check each of the radio buttons to get their optionvalues and replace the case numbers and text as appropriate.

****************************
People think it must be fun to be a super genius, but they don't realize how hard it is to put up with all the idiots in the world. (Calvin from Calvin And Hobbs)

Robert L. Johnson III
MCSA, CNA, Net+, A+
w: rljohnso@stewart.com
h: wildmage@tampabay.rr.com
 
hmmm that is fine for the Title bar of the report but i am talking about an actual text box that sits in the Report Header section.

BTW.... thank you for your help
 
Easy enough to just replace the Me.Caption with Me![NameOfField].....as long as the field is unbound, this should work fine.

****************************
People think it must be fun to be a super genius, but they don't realize how hard it is to put up with all the idiots in the world. (Calvin from Calvin And Hobbs)

Robert L. Johnson III
MCSA, CNA, Net+, A+
w: rljohnso@stewart.com
h: wildmage@tampabay.rr.com
 
Scratch that....doesn't work....

Change your text box for your "title" to a label (give it any bogus text to start) and use:

Select Case Forms![formname]![optiongroupname]
Case 1: Me![labelname].Caption = "Whatever"
Case 2: Me![labelname].Caption = "You Want"
Case 3: Me![labelname].Caption = "These To Say"
End Select


****************************
People think it must be fun to be a super genius, but they don't realize how hard it is to put up with all the idiots in the world. (Calvin from Calvin And Hobbs)

Robert L. Johnson III
MCSA, CNA, Net+, A+
w: rljohnso@stewart.com
h: wildmage@tampabay.rr.com
 
WOOHOOO that worked... now... next question.... :) bear with me if u will... i am trying to get it to populate a field (is currently a text box, but perhaps it's a label) with a count of records from the previous quarter.... know any brilliant ways to do that? I would assume its a function that gets stuffed in there once it gets a count... but based on my previous luck with getting a string to populate i dont have much hope.....

Thank you thank you thank you
 
Well, personally I woudl write a function to go to the table directly and get the count....once done return this value to a "label" on the report and display the amount.

I don't like much working with counting as the report is being generated. I just go to the table directly and get what I want.

****************************
People think it must be fun to be a super genius, but they don't realize how hard it is to put up with all the idiots in the world. (Calvin from Calvin And Hobbs)

Robert L. Johnson III
MCSA, CNA, Net+, A+
w: rljohnso@stewart.com
h: wildmage@tampabay.rr.com
 
hmmm ok... well i will dink around with it and see if i can do anything... so far i havent found a good way to do this... yet thanks again for all your help
 
let me know if you get stuck.....I can help out.

****************************
People think it must be fun to be a super genius, but they don't realize how hard it is to put up with all the idiots in the world. (Calvin from Calvin And Hobbs)

Robert L. Johnson III
MCSA, CNA, Net+, A+
w: rljohnso@stewart.com
h: wildmage@tampabay.rr.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top