473,804 Members | 3,572 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Base the value of a control in a form on another calculated control of same form

67 New Member
I have tried using the SetValue Macro to assign the value of a calculated control to another BOUND Control on the same form but have not been successful. I followed the exact format shown in MS Access help instructions.
The amount appears properly in the unbound text box (derived from data in a subform within the same form), however I cannot get that amount to then appear in a Bound Control's text box using the SetValue macro.
I am only doing it this way, since I do not know how to attach a calculated amount from the subform to directly populate a Bound Control.
(The subform contains a series of items on an invoice. The Main Form is the actual invoice, and I would like to record the total price of each of the item's costs onto a record associated with the Invoice.
I do not do code, and would like to know how I can do this using macros or just keying into a section of the Properties associated with the text Box.
Thanks for the anticipated help.
BigDaddrock
Jul 6 '10 #1
29 2943
patjones
931 Recognized Expert Contributor
What happens when you attempt to do this? Are you getting an error message of some kind? Or is it just that nothing at all is happening? Does the rest of the main form populate correctly with the data for that customer and invoice?

Pat
Jul 6 '10 #2
Bigdaddrock
67 New Member
@zepphead80
I have the SetValue macro taking place at the "At Change" position of the first Text Box (the one that is properly recording the sum amount from the SubForm). However, the destination box remains with no change. That latter one is where I would like to "paint" the sum amount appearing in the first Text Box.
Jul 6 '10 #3
patjones
931 Recognized Expert Contributor
I have to confess that I never use macros, and I am not familiar with the SetValue feature that you are talking about.

What happens when you try to enter something directly into the text box in question? Not that you'll be doing this all the time in practice - I'm just curious to see how it responds.

Pat
Jul 7 '10 #4
NeoPa
32,579 Recognized Expert Moderator MVP
I'd consider using VBA code to handle this for you. It's fairly basic stuff and shouldn't prove too much to start you off with.
Jul 7 '10 #5
Bigdaddrock
67 New Member
@NeoPa
I have determined a "work around", but am willing to learn new tricks. Based on the info provided, could you perhaps provide some kind of VBA code that I might try? Here are some details from my particular form:

Text Box in Subform!DH Orders Subform B is TotShipWt

Text Box in Form!DH ADD ORDERS is SHIPTOT
(This is Bound to the field SHIPTOT in the table supporting the Form)

Calculation I would like to have done to insert to that Text Box is
Expand|Select|Wrap|Line Numbers
  1. =Switch([TOTSHIPWT]>400,+24.95,[TOTSHIPWT]>250,+19.95,[TOTSHIPWT]>100,+13.95,[TOTSHIPWT]>80,+11.95,[TOTSHIPWT]>60,+9.95,[TOTSHIPWT]>40,+8.95,[TOTSHIPWT]>20,+6.95,[TOTSHIPWT]>10,+5.5,True,+3.5) 
  2.  
Lastly, I am able to have that last calculation populate an unbound Text Box on my Form. It goes into
Text Box in Form!DH ADD ORDERS entitled SHIPCOST

I would like to be able to directly populate the Text Box SHIPTOT from the subform (eliminating the need for Text Box SHIPCOST. However, I would be willing to populate SHIPTOT from SHIPCOST, if this eases things since they are on the same form.

Thanks for the assistance.
Jul 7 '10 #6
patjones
931 Recognized Expert Contributor
I'll tell you what I think you need to do to solve the immediate problem, then add a disclaimer.

Putting this code in the After Update event of TOTSHIPWT should do it for you:

Expand|Select|Wrap|Line Numbers
  1. Forms![DH ADD ORDERS]!SHIPTOT.SetFocus
  2. Forms![DH ADD ORDERS]!SHIPTOT = Switch(Forms![DH ADD ORDERS]![TOTSHIPWT]>400,+24.95,Forms![DH ADD ORDERS]![TOTSHIPWT]>250,+19.95,Forms![DH ADD ORDERS]![TOTSHIPWT]>100,+13.95,Forms![DH ADD ORDERS]![TOTSHIPWT]>80,+11.95,Forms![DH ADD ORDERS]![TOTSHIPWT]>60,+9.95,Forms![DH ADD ORDERS]![TOTSHIPWT]>40,+8.95,Forms![DH ADD ORDERS]![TOTSHIPWT]>20,+6.95,Forms![DH ADD ORDERS]![TOTSHIPWT]>10,+5.5,True,+3.5)

My disclaimer is this. What you are doing here amounts to changing the underlying recordsource, which is not always wrong. But in this situation it doesn't make sense to store this calculation in a table in your database.

Take age as an example. If you have a table of people and dates of birth, you could store age in the table also; however, doing so is actually redundant, because the table already holds date of birth. Whenever age is needed (in a report, for instance), it can simply be calculated at that time. Not to mention that age is a constantly changing quantity...so as soon as the column is updated, many of the values will very soon become out of date.

In your situation, I would store the various weight-to-price conversions in a look-up table instead of using the Switch statement, and then whenever you need to obtain such a conversion for any purpose, you can grab the value from the table.

Pat
Jul 7 '10 #7
NeoPa
32,579 Recognized Expert Moderator MVP
I very much support Pat's comments on normalised data (Basically not storing the same info more than once but I strongly recommend checking out Normalisation and Table structures for the full story).

That said, as a first step on the path to VBA programming (as opposed to the old macro approach) I would say :
  1. Start off by creating the AfterUpdate event procedure for the control [TotShipWt] in your [DH Orders Subform B] form. Select the control and, ensuring properties are visible, set the AfterUpdate property to [Event procedure] from the dropdown.
  2. This creates the template shell within which to add your code. Add the code below as an example. This is still not a recommended approach, but will probably help you understand better how things work in the VBA world.
Expand|Select|Wrap|Line Numbers
  1. Private Sub TotShipWt_AfterUpdate()
  2.     With Me
  3.         .Parent.ShipTot = Switch(.TotShipWt > 400, 24.95, _
  4.                                  .TotShipWt > 250, 19.95, _
  5.                                  .TotShipWt > 100, 13.95, _
  6.                                  .TotShipWt > 80, 11.95, _
  7.                                  .TotShipWt > 60, 9.95, _
  8.                                  .TotShipWt > 40, 8.95, _
  9.                                  .TotShipWt > 20, 6.95, _
  10.                                  .TotShipWt > 10, 5.5, _
  11.                                  True, 3.5)
  12.     End With
  13. End Sub
Jul 8 '10 #8
Bigdaddrock
67 New Member
Thanks for the explanation. I appreciate your help.
Jul 8 '10 #9
NeoPa
32,579 Recognized Expert Moderator MVP
You're very welcome :)
Jul 8 '10 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

5
2397
by: Georges Heinesch | last post by:
Hi. Is it possible to put a tab control inside another tab control. I tried it several times, but for some reason this doesn't seem to work. Can someone confirm this, or tell me what the trick is. Thanks. --
5
27560
by: Paul Mendez | last post by:
I am creating a form with a tab control containing 10 tabs. and what I want to do is on only on of the tabs, I want a sub section of tabs. So what it ends up being is one main tab control with another tab control embedded into only one of the tab pages. The problem I am getting is when I insert the sub section tab control into one of the tabs from the main tab control, the sub section tab control appears in every tab in the main tab...
6
6676
by: Tom Rowton | last post by:
This one has me a bit confused and I'm not finding what I need in the MSDN or by searching these forums, so here goes... I have a rather large, complex code-in-page WebForm (don't ask) and a section of that Form is 4 or 5 ASP:Panels pretending to be a set of Tabs, each with its own section of the form.
3
7144
by: qwerty | last post by:
I have two User controls in a page. Them ID-propertys are example UC1 and UC2. In code behind file they are declared: Public UC1 As UC1 Public UC1 As UC1 From the page I can call them with their name (UC1 and UC2) and access their public propertys and functions.
1
1436
by: Jonah Olsson | last post by:
Hello, I'm trying to build an "add-on" to an already existing custom web user control. The old control collects some user data and saves it to a database. The new control should collect some extra info from the user and add it to a new table in the database. The old control should not be re-written (at least not now..), so I need a way of capturing the click event of the Save button in the old control. This event should trigger a...
2
1289
by: DJ | last post by:
Hi, I have a user control that produces and maintains a student form for test enrollment. It contains all functionality such as adding, editing, suspending, etc., a student from a selected test instance. The main page uses the student form control (above), plus a control that produces the button pad (for administrative functionality) and one that produces a student roster.
2
10105
by: kumarpappu | last post by:
hello - I am newbie in winforms and c#. i have a mainform.cs and it has 2 user controls - leftView and rightView. In leftView.cs i am instantiating a new clientLeftView(another user control) and also the clientRightView(another user control) Now clientLeftView has a lstClient - list box.
2
1561
by: reidarT | last post by:
I have 3 fields in an aspx page. The 3. field should be the sum of field A and field B I use OnTextChanged to calculate the sum in field3. At the same time I want to insert the content of theese 3 fields into a row in a table. The problem is that I need 'postback is true' on the textfields to get an immediate calculation and then the insert action is triggered. reidarT
4
1695
by: Michael R | last post by:
In a continous form, I need txbControl1 to be conditioned according to txbControl2. txbControl1 control source is: =DSum("Amount","Loans","Id=Forms!Cities!Customers.Form!Id") txbControl2 control source is of the subform's record source table So the condtional formatting of txbControl2 would be: txbControl1.value = 1000
2
1324
by: erobinso | last post by:
In IE it is simple to address form fields with the same name in multiple forms, such as: document.firstform.mode.value='open'; document.secondform.mode.value='new'; etc But in Firefox I am forced to use getElementById, as in: document.getElementById.value='open';
0
9704
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9569
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10558
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10302
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10069
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5503
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5636
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4277
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2975
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.