Populate a user form with a formula to calculate units per hr

From the time sheet form button, can the units per hour be calculated
StlFunction-Analisys-2015-v1f.xlsm
bjfulkersonAsked:
Who is Participating?
 
broro183Connect With a Mentor Commented:
hi,

Try adding the following code into the code behind the TimeSheetEntry Form module. This seems to hold up okay under some light testing.


Private Sub TxtTime_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    Call CalcAndUpdateUPH_tbx
End Sub

Private Sub TxtUnits_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    Call CalcAndUpdateUPH_tbx
End Sub

Sub CalcAndUpdateUPH_tbx()
With Me
        'test that both fields are populated.
        If Len(.TxtTime.Value) * Len(.TxtUnits.Value) Then
            'validate that the entries are numeric.
            If IsNumeric(.TxtTime.Value) And IsNumeric(.TxtUnits.Value) Then
                .TxtUPH.Value = .TxtUnits.Value / .TxtTime.Value
            End If
        End If
    End With
End Sub

Open in new window


hth
Rob
0
 
Phillip BurtonDirector, Practice Manager and Computing ConsultantCommented:
Don't understand the question.
0
 
bjfulkersonAuthor Commented:
Rob,
When you say behind, what does that mean?
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
bjfulkersonAuthor Commented:
I added it to the top of the TimesheetEntry and it worked great!  Thanks for adding the explanations too!
0
 
broro183Commented:
Sorry, I didn't word that very well.

It may just be my settings but when I double (left) click on the TimeSheetEntry item in the Forms folder within the Project Pane of the VBE, the result is that the Userform appears (on the right for me). To see the code relating to the Userform, I press [F7] or right click on on the item in the lefthand pane & choose "view code". This then shows the code relating to the userform eg "Private Sub UserForm_Initialize()" or "Private Sub Calendar1_Click()".

I consider this code as being "behind" the userform.

Rob
0
 
bjfulkersonAuthor Commented:
Got it . Thanks
0
 
broro183Commented:
Awesome, I'm pleased I could help :-)

Now that it is a calculated field, I suggest changing the appearance of the textbox so that users can easily recognise that they don't need to populate it (eg "grey it out" by changing the backcolour to something like &H80000000&.
Or, if you want to get more complicated, you could allow users to enter values into any two of the three fields & then have the code calculate whichever one is the remaining empty field.

Rob
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.