By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
426,140 Members | 1,301 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 426,140 IT Pros & Developers. It's quick & easy.

displaying values in text boxes

100+
P: 250
this doesnt seem that difficult but i cant figure it out... i have a text box on my form that displays a number. i would like the form to automatically put half of that number in one text box and the other half in another text box... and update if i change that number... is this possible... thanks!
Feb 14 '09 #1
Share this Question
Share on Google+
5 Replies


missinglinq
Expert 2.5K+
P: 3,532
The assignments will have to be done in the original textbox AfterUpdate event. But you're going to have to do a much better job of explaining what you mean by "half of that number in one text box and the other half in another text box!" What exactly composes each "half?"

Linq ;0)>
Feb 15 '09 #2

100+
P: 250
Sorry for the generalization. I mean if I have a text box with the number 600 in it. I would like two other text boxes to display 300 each. If that's possible. Thanks for your help!
Feb 15 '09 #3

missinglinq
Expert 2.5K+
P: 3,532
Where OriginalTextbox holds the original number:
Expand|Select|Wrap|Line Numbers
  1. Private Sub OriginalTextbox_AfterUpdate()
  2.  If Not IsNull(Me.OriginalTextbox) Then
  3.   Me.TextboxA = Me.OriginalTextbox / 2
  4.   Me.TextboxB = Me.OriginalTextbox / 2
  5.  Else
  6.   Me.TextboxA = Null
  7.   Me.TextboxB = Null
  8.  End If
  9. End Sub
If TextboxA and TextboxB are bound to a field in the underlying table, this is all you need. Simply replace the three textbox names with your actual names.

Having said that, calculated fields such as TextboxA and TextboxB should never really be stored in the underlying table! They should simply be re-calculated as needed. To do this as you move from record to record, in addition to the code listed above, you'll need the same code in the Form_Current event:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Current()
  2. If Not IsNull(Me.OriginalTextbox) Then
  3.   Me.TextboxA = Me.OriginalTextbox / 2
  4.   Me.TextboxB = Me.OriginalTextbox / 2
  5.  Else
  6.   Me.TextboxA = Null
  7.   Me.TextboxB = Null
  8.  End If
  9. End Sub
If you need to use TextboxA and TextboxB in a report, create a calculated field on your report and use the same expressions as above.

Linq ;0)>
Feb 15 '09 #4

100+
P: 250
ok the code you gave me works great... but i was wondering if its not a good idea to store the figures in an underlying table... what would be the proper coding to add up a few textboxes containing the results of the code you have just given me and some number that i will input myself and having them display in a totals textbox. i only have 1 record displaying information and i want it to update according to what numbers i put in. i hope im clear enough for you.. if you need more info please let me know... thanks for your help
Feb 15 '09 #5

NeoPa
Expert Mod 15k+
P: 31,419
The code you're after would have to match the TextBoxes you need summed. This is only possible if you specify what you need more precisely, including all the names.
Feb 16 '09 #6

Post your reply

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