PDA

View Full Version : Is it possible to auto-calculate and auto-populate ablank field based on listboxx



wedd
01-20-2011, 02:35 AM
Hi all, I have a textbox1 called number of hours and based on the user's selection of starting times(listbox1) and finish times(listbox2) from a listbox, I would like the textbox1 (number of hours) to automaticatically generate or calculate the number of hours and auto-populate in this field the amount of hours the user wants to use a computer at an Internet cafe for example...Is it possible to do this using either vba, expression, macro, query etc? If so, how can this be done?

Thanks for your contributions:friends:

CreganTur
01-20-2011, 07:21 AM
Either on your form's change event or the change event for each combobox just put something like this:

TextBox1.value = combobox1.value - combobox2.value

hansup
01-20-2011, 08:57 AM
I created a simple form with 2 text boxes, both formatted as General Date: txtStart and txtEnd. Then I added a third text box, txtHoursElapsed, and set its Control Source to:
=DateDiff("h",[txtStart],[txtEnd])
Upon any change to txtStart or txtEnd, txtHoursElapsed "automagically" updates to display the difference, in hours, between the 2 Date/Time values. If either txtStart or txtEnd is Null, txtHoursElapsed will be Null ... which seems like the correct behavior to me.

You mentioned list boxes. I used text boxes in my example because they were quicker for me to create. But the same principle will apply to list boxes ... unless your list boxes are multi-selectable ... in which case none of this makes sense anyway.

wedd
01-20-2011, 01:21 PM
Thanks!