Automatically Update Textbox Value on Report Load (1 Viewer)

vagues0ul

Registered User.
Local time
Today, 05:59
Joined
Sep 13, 2018
Messages
103
I am having issue while updating textbox value on report load. I want the textbox values to load automatically instead of clicking on it while the reports load because on click every box display its value to all the present box on the report.

this is my script

Private Sub Text148_Click()
Text148.Text = Round((m1totals.Value / markstotal.Value) * 100, 2)

End Sub


i dont want it to be done ONCLICK but on report load
 

June7

AWF VIP
Local time
Today, 04:59
Joined
Mar 9, 2014
Messages
5,423
Why using Text property? Probably really want to set Value but this cannot be done with textbox on report. Since Value is default, no need to type it.

If you are trying to save to table - why? Why don't you put expression in ControlSource and calculate when needed?

Really not clear what you are trying to accomplish.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 08:59
Joined
Feb 19, 2002
Messages
42,970
The Load property runs ONCE when the report is loaded. Your expression appears to depend on data from the report's RecordSource. That means that you want the code to run for each row so the Format event would be better.

Additional comments on syntax:

In Access forms/reports, the .value property is the default and the .text property is only available while the control has the focus so I can't imagine this working.

For efficiency, use Me.controlname rather than controlname.value

Me. is available ONLY in the code module of the form/report. It qualifies the variable so that Access knows where it is defined. It also provides intellisense. See what happens when you type:
Me.controlname.
you'll get a list of properties and methods

And finally, it is really poor practice to leave controls with the default name. BEFORE you add code to events or reference a control, always rename it so that it has a meaningful name. When you drag controls from the bound RecordSource, Access gives them the same name as the ControlSource. Common practice is to rename them with a prefix such as txt or cbo or cmd.
 

Users who are viewing this thread

Top Bottom