Change Label Caption on Open

G

Guest

Hello

I have a crosstab query that dynamically generates a report. I have to place a committee name on the report when the report it open. Unfortunately, the properties for the caption do not appear when I use the On Open function. How can I change the caption of a label or text field at that point

TIA

Eric
 
M

MGFoster

Eric said:
Hello,

I have a crosstab query that dynamically generates a report. I have to place a committee name on the report when the report it open. Unfortunately, the properties for the caption do not appear when I use the On Open function. How can I change the caption of a label or text field at that point?

Change Label Caption:

Me!Label_Name.Caption = "New Caption"

TextBoxes do not have captions.
 
G

Guest

Actually, whether it's the caption for a label or the text of a text box - the option does not exist on the On_Open functioni of a report - is there another way to get around this

Eric
 
M

MGFoster

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I have the ability to change the captions of Labels in the On Open
event of my reports. E.g.:

Private Sub Report_Open(Cancel As Integer)

Me!Label_name.Caption = "New Caption"

End Sub

If you are talking about the column names of the report's query -
you're right they do not exist at the report's OnOpen event. What
I've done in the past is to run the report's record source query from
the OnOpen event & get the column names, change the label captions and
then continue w/ the report (which will run the query again to fill
the report). E.g. (air code):

' called from the report's OnOpen event
dim db as dao.database
dim qd as dao.querydef
dim rs as dao.recordset
dim fld as dao.field

set db = currentdb
set qd = db.querydefs("query name")
set rs = qd.openrecordset()

' Get column names (Field.Name)
if not rs.eof then
for each fld in rs.fields
' do what you want here - change label.captions
debug.print fd.Name
Next fld
end if


MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQE3zqIechKqOuFEgEQKQCgCfUEMeutQsiuaeiHAJIBAHoAZWRP0AoLp6
8C0er92kAYheUI98T0wMQcrB
=gsYo
-----END PGP SIGNATURE-----
 
G

Guest

Thanks MgFoster

What I want to do is get the name of a text box from a form that opens the report. The record source for the report is a crosstab query, so I can't include the field in the record source

Thanks

Eric
 
M

MGFoster

Eric said:
Thanks MgFoster,

What I want to do is get the name of a text box from a form that opens the report. The record source for the report is a crosstab query, so I can't include the field in the record source.

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Not very clear Eric. If there is a form that opens the report you
must know the names of all the TextBoxes on that form since you are
creating the form (aren't you?). Is it the value of one of the
TextBoxes you want to get? If so, where do you want to get it - while
in the form or while in the report?

How to get the value of a TextBox while code is running on the
form/report:

Dim strTextBoxValue As String
strTextBoxValue = Me!txtTheTextBox

Getting the value of a TextBox from another form/report:

Dim strTextBoxValue As String
strTextBoxValue = Forms!frmOtherForm!txtTheTextBox

You can get the TextBox names from the report's OnOpen event or during
one of the report's other events. Here is a method that will allow
you to enumerate all the TextBox names, and their values, of a form
from the report's OnOpen event (it could be used in any Sub or
Function you define):

Private Sub Report_Open(Cancel As Integer)

Dim frm As Form
Dim ctl As Control

Set frm = Forms("form name")

For Each ctl In frm.Controls
If TypeOf ctl Is TextBox Then
Debug.Print ctl.Name, ctl.Value
End If
Next

Set ctl = Nothing
Set frm = Nothing

End Sub

You have to replace the "form name" with the name of the form from
which you want to get the TextBox names. That form has to be open
when the code runs.


MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQE9+yIechKqOuFEgEQJDzQCeIHzjTl1S/sbNhFM+lNxIeGiLDCoAoPl0
dY7k8UCRvJZ0TpBa1VfNHr0t
=NMt6
-----END PGP SIGNATURE-----
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Setting Report label caption from VB6 2
can grow label 1
Dynamic Report-Caption 5
dynamic caption 1
Word problem with caption in MS Word 0
Dynamic Crosstab Report help 0
Label Control - Caption Text Format 1
label captions 2

Top