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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VB code and Reports 1

Status
Not open for further replies.

clansullivan

Programmer
Jul 18, 2005
7
US
I need to pass a value from the open event in a Access report and display it on the actual report.

This has got to be easy, but I don't know much about Access!'

thanks
 
....and yet you know that Access reports have open events...

so what kind of control were you looking to display this value in ??

and what is the control's name ?



Rgds, Geoff

Three things are certain. Death, taxes and lost data. DPlank is to blame

Please read FAQ222-2244 before you ask a question
 
Yes, well I know VB ok, and I know how to get to the code in a report, but the Access specific stuff I don't know.

I have a textbox on the report, as a simple string variable in the code.

thanks
 
Well, according to the easily available object model (press F2 when in the VBE), a textbox has 2 suitable properties...
.text
.value

take your pick


Rgds, Geoff

Three things are certain. Death, taxes and lost data. DPlank is to blame

Please read FAQ222-2244 before you ask a question
 
Yes that's the problem I'm in Access 2000 and although I get the intellisense for txtUnsatisfactory, the properties available are not normal text box properties. There is no text or value property.

thanks
 
In which case you will need to use a label and the .CAPTION property

Rgds, Geoff

Three things are certain. Death, taxes and lost data. DPlank is to blame

Please read FAQ222-2244 before you ask a question
 
Thanks again - but unfortunately the label gives me the same generic proporties as the textbox
 
and have you looked at the properties box rather than intellisense ?? or even tried it in code?



Rgds, Geoff

Three things are certain. Death, taxes and lost data. DPlank is to blame

Please read FAQ222-2244 before you ask a question
 
Erm - there are seven Access fora here at this site, do a forum search at the top, there's even one specific forum for Access reports (forum703)...

...and no, you can't assign any control values in the on open event of the report, the usual way is to assign in the on format event of the section in which they reside - and - the default property of Access text controls, is the .value roperty, the .Text property is seldom used, as it demands the control to have focus to be utilized...

Roy-Vidar
 
erm - I know you are an access expert Roy but I created a bound form, added a label to it and successfully changed the caption property of the label in the form open event using

labelName.caption = "Test String"

worked fine.....

Rgds, Geoff

Three things are certain. Death, taxes and lost data. DPlank is to blame

Please read FAQ222-2244 before you ask a question
 
- yeah - and text control, as in the question, not a label caption...

Roy-Vidar
 
apologies - I meant a report - just more used to dealing with forms........and we had moved on from text boxes to labels as per my post from 19 Jul 05 12:14 as we had already discovered that it wouldn't work with textboxes (plus your post says controls not textboxes)

I will repeat.

I created a bound report, added a label and changed the label caption within the open event.

We had already discovered that you cannot do this with textboxes so I suggested labels instead - personally, I don't see any problem with using them instead of textboxes to display data but if you know something I don't Roy, please feel free to enlighten me




Rgds, Geoff

Three things are certain. Death, taxes and lost data. DPlank is to blame

Please read FAQ222-2244 before you ask a question
 
I don't see any problems with a label control caption approach vs assigning value to a control, but it does seem the OP did...

Assigning information to reports can be done several ways. For instance using the controlsource of a text control to reference a form control on an open form (=forms!frmMyForm!txtMyControl), or a public function which retrieves a value from a variable (=GetMyValue). It can also be done programatically, as in this case.

When reading quickly through the thread, the usual basic suspect of such arose, you cannot assign values to controls (values as opposed to caption) in the on open event of reports. The other frequent culprit for this error, but (also) occurring in other events so not relevent here, would be if the control had a controlsource.

With regards to the semantics, perhaps I wasn't precise enough? I tried to refer to assigning values to controls - a label control does not have a .Value property - then I continue to discuss the .Value and .Text properties of text controls, of which, as far as I know, only the .Value property can be used when working with reports (and, as it is the default property, lot of developers prefer not to specifying it). I did not refer to other properties...

The persistant challenge, also after your suggestion of using the .Caption property, lead me to suggest what I perceive to be the most common programattic approach to displaying such information on reports - assigning values to controls in the on format event of the section in which they reside. And no, I did not bother trying to figure out why the Label .Caption approach did not work, as it should normally work. One guess could be that when the label control was referenced, the property was omitted (I think that should give the 438 - Object doesn't support this property or method vs 2448 You can't assign a value to this object, which will usually arise when trying to assign values to controls in the on open) or that it was attempted on some control that wasn't really a label (would probably bring up the 438 again).

Reading a bit more closely, it seems the OP relied on the "intellisence" dropdown, which can't be said to be the most fruitful experience when working with Access reports. One funny thing, is for instance the .IsVisible property of controls, which is usually available through "intellisence" in forms, but not reports, and the only place where this property can be set (according the the help files, that is), is the on print event of report sections (it can be tested also in for instance the on format event of report sections, but not used on forms)... One would need to rely more upon knowledge, than the "intellisence". But - one doesn't need to know it all by heart, it's usually enough to know that in addition to using the property dialog, using the help file on different control types, then study the information in the properties, methods and events list would often be of great assistance - and often show differently than the "intellisence" dropdown.

But, the members frequenting the reports forum probably knows a tad more on reports, which is also why I pointed there...

Don't know if this rant is any help to anyone, though, except perhaps some of it might explain a bit more on some of the amusements of working with Access...

Roy-Vidar
 
that's good info Roy

think the lesson here is not to just trust intellisense

Looks like 2 options

1: Use a label and the caption property within the open event
2: use a different control within the format event

Rgds, Geoff

Three things are certain. Death, taxes and lost data. DPlank is to blame

Please read FAQ222-2244 before you ask a question
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top