Solved

Setting a textbox's controlsource in VBA on a report

Posted on 2001-08-21
8
537 Views
Last Modified: 2012-05-04
Simple question,

I have an unbound txtbox on a report, we can call it txtValue.  In the report I want to take the values from three other txtboxes that are dynamically generated, sum them, and have that value displayed in txtValue.  I don't understand why when I write the code and I reference txtValue that it doesn't give me the option for controlsource.  I have the summed value, i just don't have a way to give it to txtValue so it can be shown on the report.

Please help

Thanks,
Boody
0
Comment
Question by:boody
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
8 Comments
 

Author Comment

by:boody
ID: 6409853
By the way, I'm using a recordset to get the values that I want for the other textboxes.
0
 
LVL 4

Expert Comment

by:maatthias
ID: 6409857
Try summing it in the report detail's OnFormat event.
0
 
LVL 58
ID: 6409876
Reports are a bit special.  In the way that controls and fields work together.  The approach is not to set the controlsource, but simply fill the control in with a value:

  Me![mycontrolname] = 1

  Would put a "1" in the control.  Replace the "1" with the rsult of your calculation.

Jim.
0
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 

Author Comment

by:boody
ID: 6409935
Jim,

How do I replace the 1 with calculation?
0
 
LVL 58
ID: 6409972
You said you had the summed value correct?  Just do:

 Me![mycontrolname] = <summed value>

 in the OnFormat event of the section where the control is located.

  or did I miss something?

Jim.
0
 

Author Comment

by:boody
ID: 6410042
Actually, I have five textboxes that are receiving values.  I'm just trying to get the total of the first three. I got the total by using a variable and looping it through the first three.  That's in VBA, but I can't use that in the expression builder.

My report looks like this:

Year1 ... Year2 ...Year3 ...Year4 ...Year5 ... 3Yeartotal
12345.....12345....12345....12345....12345.....37305

I don't have a running sum or anything like that. All of the year captions and values get their data from a recordset since they change depending on what the year the user wants to specify.
0
 
LVL 4

Expert Comment

by:maatthias
ID: 6410063
In that case there shouldn't be any need for coding in OnFormat event.  Just set the textbox's controlsource as an expression sum it up.
0
 
LVL 58

Accepted Solution

by:
Jim Dettman (Microsoft MVP/ EE MVE) earned 20 total points
ID: 6410099
Then in the OnFormat, simply do:

 Me![year3Total] = Me![Year1] + Me![Year2] + Me![Year3]

for example (but you need to use your actual control names)

Jim.
0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

624 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question