John Q. Noob
John Q. Noob

Reputation: 181

Possible to manipulate text labels in report section headers using VBA? (MS-ACCESS)

Possible stupid question here...

But is it possible in MS-Access to programmatically manipulate text label captions in such a way that that a different caption will appear in the header of each report section?

Ie., The design view shows a text label object in the GroupLevel zero header, with a default caption of "blah"....but upon execution of a Report_Load() sub, the actual text displayed is different for each section in the report? Say, simply "Section 1", "Section 2', "Section 3" and so on?

My suspicion is that this is not possible, but just wondering if anyone has some creative ideas how to make it work.

I realize that there are other/better ways of accomplishing the same thing...but is such a thing possible using VBA and Label objects specifically (at the moment, this is an external constraint and one that I cant change).

EDIT: https://drive.google.com/open?id=1PID58qMyp_rNxv9tsQk38-Co9sDOFgzY

EDIT 2: Original post specifically designated LABELS as the only object for an acceptable solution. Edit to include LABELS and TEXT BOXES...which of course makes the question nearly trivial. Apologies to @peakpeak for my lack of clarity!

Upvotes: 0

Views: 1626

Answers (2)

John Q. Noob
John Q. Noob

Reputation: 181

Actually, thank you for your help, but I have found something that appears to function as a decent work-around within the constraints I described above. Strictly speaking, this does not satisfy the terms of the question as originally asked (-1 to me for lack of clarity, and apologies to @peakpeak, who admittedly had essentially zero chance of answering this question as asked), but it this is close enough that it solves my immediate problem:

Change the object intended to contain my dynamic text from a label to a text box (duh!), keep all formatting settings, etc. the same so that the graphical presentation is unchanged.

Set the Control Source of the new text box to a public function, where the argument of the function is the name of a relevant field in the underlying query ("tName" in the linked example), so that the dynamic text box has a control source "=GetText([tName])" and the GetText() function is defined in the appropriate module for the report, and defines the text as desired, e.g.:

GetText(tName as String) as string

SELECT Case tName

Case "Albert"

GetText = "Section 1"

Case "Barry"

GetText = "Section 2"

Case Else

GetText = "Section 3"

'and so on

End Select

`

End Function

Upvotes: 0

user2261597
user2261597

Reputation:

You can change the caption with

Me.<name of header>.Caption = "whatever"

Select Properties for the header in design view and find out and/or change the Name property. Me assumes that the VBA code is located under Microsoft Access Class Objects in the form you want to manipulate.

Upvotes: 1

Related Questions