473,396 Members | 1,693 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Adding up fields

Hi,

This would be very simple but I cant seem to get it working, all I am trying to do is get textbox "a" and textbox "b" to add together so that textbox "c" displays the total of the two automatically.

Any help would be great, Thanks.

Rob.
Sep 2 '08 #1
5 1799
yaaara
77
You may try using the following code :

Expand|Select|Wrap|Line Numbers
  1. Private Sub textboxA_Change()
  2. textboxC.value=textboxA.value+textboxB.value
  3. End Sub
  4.  
  5. Private Sub textboxB_Change()
  6. textboxC.value=textboxA.value+textboxB.value
  7. End Sub
  8.  
  9.  
  10.  
Doing this should display the sum of both the text boxes when the value in any of them changes.

Do let us know the outcome.
Sep 2 '08 #2
Stewart Ross
2,545 Expert Mod 2GB
Hi. It depends on whether or not your textboxes are bound to underlying fields. If they are, the data type of the value contained in the textbox is determined by the data type of the underlying field. If they are unbound, the contents are treated as text values (not numbers).

In the bound case, and assuming that the underlying fields are numbers, then in C's control source you enter:

=[a]+[b]

But if they are unbound, you will need to convert them to an appropriate type either using CLng for long integers or CDbl for double-precision floating point:

=CLng([a]) + CLng([b])
=CDbl([a]) + CDbl([b])

If you try

=[a]+[b]

on text values it will result in their concatenation:

'1' + '2' = '12'

-Stewart

ps @ Yaara: no need for code in this case - the control source can be set to be the sum of the two fields directly as shown. If code was used it would need to be associated with an After Update or similar event.
Sep 2 '08 #3
yaaara
77
Actually you are right (as always) Steve.. I quite often get confused with the coding pattern in VB6 against VBA in Access.. The code I mentioned would have worked perfectly for VB6 but in VBA, it surely needs to be associated with either BeforeUpdate or AfterUpdate event. Changing the ControlSource does give the required output :-)
Sep 2 '08 #4
Stewart Ross
2,545 Expert Mod 2GB
Actually you are right (as always) Steve..
Thanks, Yaara.

I'm used to people calling me Stuart a lot, though rarely Steve... but what's in a name anyway?? I appreciate your kind words in any event.

-Stewart
Sep 2 '08 #5
yaaara
77
Actually I've met several people with your name and all of them liked them to be called Steve... Will call you Stuart as per your liking..

As for that famous quote "What's in a name?" by Shakespeare (or whichever way you spell it), I'd like to say that he did mention this statement, but he didn't forget to write his own name below it.. So there has to be something in a name? ;-)

Thanks, Yaara.

I'm used to people calling me Stuart a lot, though rarely Steve... but what's in a name anyway?? I appreciate your kind words in any event.

-Stewart
Sep 2 '08 #6

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

Similar topics

1
by: Anand | last post by:
Hi i am having trouble adding a recordset into the access database, the code seems to be working fine it passs and parses through all variables just fine without showing any errors and also when i...
6
by: Jamie Fryatt | last post by:
Hi everyone, here's what id like to do. I have a table with 2 fields, name and value I need to be able to add multiple records quickly, for example I need to add name value abc 1...
0
by: Jozef | last post by:
Hello, I have a list box that I'm adding items to. The line that adds the items is as follows; lstUserRoster.AddItem (iCount & ";" & rs.Fields(0) & ";" & rs.Fields(1) & ";" & rs.Fields(2) &...
2
by: brenda.stow | last post by:
error msg " An error occured while referencing the object. You tried to run a visual basic procedure that improperly references a property or method of an object" This msg occurs everytime I add a...
5
by: Kosmos | last post by:
I have traveled the world and the seven seas and I have yet to come up with an answer to this question.... So I'm adding an attachment to an email from access... The following is the code: ...
2
by: Kosmos | last post by:
Alright so I've got this Outlook code written in VBA in Access. The first part, which works, records information about appointment times based on the required days before notification of certain...
6
by: Mangler | last post by:
Say I have to different recordsets that have the fields: rsA.Fields.Item("A").Value ,rsB.Fields.Item("B").Value How would I add those to fields? It may be my inexperience but when I tried...
4
by: jaz215 | last post by:
hi! how do i add a record in a database without using the datacontrol and adodc. i want to rework my code to using purely codes and not being dependent on the design on vb. so far i have. Set rs...
18
omerbutt
by: omerbutt | last post by:
AJAX PROB WITH MULTIPLE RECORDS helo iam having problem in ma code will any body look out an help, i am trying t add sale record in the database and the checkthe quantity of the part slod and...
2
by: Steve | last post by:
I have zero experience with ODBC. If I have an Access frontend connected to a SQL Database using ODBC, are the tables connected like a frontend/backend Access database where the the tables you see...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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,...
0
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...

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.