help creating function that combines multple text box values

D

dibblm

I have a form with 4 columns of 31 text boxes. These are used for
calculating time in and time out.

example of one row..

<Text Box1> <am/pm drop down1> <text box 2> <am/pm2> <Label showing
results1>
<Text Box3> <am/pm drop down3> <text box 4> <am/pm4> <Label showing
results2>
<Text Box5> <am/pm drop down5> <text box 6> <am/pm6> <Label showing
results3>
<Text Box7> <am/pm drop down7> <text box 8> <am/pm8> <Label showing
results4>


after someone enters a time in and a time out I need the results to display
in the label for each row.

Instead of writing code for the event ( after lost focus on the last am/pm)
for each row. like such.
textbox1 + textbox2 = label 1 (But alot more in depth) Can i write a
function that can be called so I dont have to specify each and every text
box and return the results to every label?
 
J

John Nurick

Access forms don't let you use control arrays the way you can in VB. But
you might try something like this:

1) set the Tag property of each of the four TextBoxes in row 1 to "01",
in row 2 to "02", and so on up to row 31, "31"

2) set the Name property of each of the 31 labels to something like
"lblTime01" to "lblTime31".

3) Use code something like this (untested air code):

Dim arDays(30) As Double 'or whatever type is needed
Dim j as Long
Dim C as Control

For Each C in Me.Controls
If C.Type = acTextBox Then
j = Val(C.Tag)
If j >= 1 And j <=31 Then
arDays(j - 1) = arDays(j - 1) + C.Value
End If
End If
Next

For j = 1 to 31
Me.Controls("lblTime" & Format(j, "00")).Caption _
= Format(arDays(j-1), "0.00") 'or whatever's needed
Next
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top