Check value of three text box controls on a form then build text string with results (1 Viewer)

kpaull

New member
Local time
Today, 15:16
Joined
Mar 22, 2009
Messages
6
A very junior programmer here. Needing some help to get the desired results with my code:

What I need my code to do:

1) I want VBA code to examine the value of three textbox controls:
txtbox_RT , txtbox_OT, txtbox_DT "Regular Time, Over Time, and Double Time"

2) Then based on each the values being numeric and > 0, append to a string.

e.g. #2- Lets say for example, txtbox_RT = 10, txtbox_OT = 3, and txtbox_DT = 0
The string should only show "RT = 10 OT =3"

3) Set the string the above string as the value in txtbox_TotalTime.


My Code:


If IsNull Me.txtbox_DT Then
Me.txtbox_TotalTime = "DT:" & Me.[txtbox_DT]

If IsNull Me.txtbox_OT Then
Me.txtbox_TotalTime = "OT:" & Me.[txtbox_OT]

If IsNull Me.txtbox_RT Then
Me.txtbox_TotalTime = "RT:" & Me.[txtbox_RT]

Else

Me.txtbox_TotalTime = "RT:" & Me.[txtbox_RT] & "OT:" & Me.[txtbox_OT] & "DT:" & Me.[txtbox_DT"RT:" & Me.[txtbox_OT]

End IF



What you already know my code does:

My code sets Me.txtbox_TotalTimer to "RT:10 OT:3"

If there is value of 1 in Me.txtbox_DT (other values in my txtboxes remain as "txtbox_RT = 10, txtbox_OT = 3") my code sets Me.txtbox)_TotalTimer to "" meaning nothing/ blank.

Any guidance would be appreciated.

Thank you in advance!

:banghead:
 

plog

Banishment Pending
Local time
Today, 14:16
Joined
May 11, 2011
Messages
11,638
Before formalizing your code you need to formalize your logic. Write a logically complete description of what you want to happen.

You have 3 variables, each of which have 2 possibilities (>0 or not). That means you have 6 permuatations to account for. I am sure a lot of those can be accomodated together, but so far you have not done that. So, tell us how to handle each of those 6 permutations.

1. DT>0, RT>0, OT>0
2. DT>0, RT>0, OT NOT >0
3. DT>0, RT NOT >0, OT NOT>0
4. DT NOT >0, RT NOT >0, OT NOT >0
5. DT NOT >0, RT>0, OT>0
6. DT NOT >0, RT >0, OT NOT >0

So far you've only explained #5 and its hard to discern from your code the other 5. So formalize your logic with simple words to show what those other permutations yield.
 

kpaull

New member
Local time
Today, 15:16
Joined
Mar 22, 2009
Messages
6
Okay, thanks for this guidance! See my responses below:

1. DT>0, RT>0, OT>0

Set Me.txtbox_TotalTime = "RT: " & txtbox_RT & "OT: " & txtbox_RT & "DT: " & txtbox_DT

2. DT>0, RT>0, OT NOT >0

Set Me.txtbox_TotalTime = "RT: " & txtbox_RT & "DT: " & txtbox_DT

3. DT>0, RT NOT >0, OT NOT>0

Set Me.txtbox_TotalTime = "DT: " & txtbox_DT

4. DT NOT >0, RT NOT >0, OT NOT >0

Set Me.txtbox_TotalTime = ""

5. DT NOT >0, RT>0, OT>0

Set Me.txtbox_TotalTime = "RT: " & txtbox_RT & "OT: " & txtbox_RT

6. DT NOT >0, RT >0, OT NOT >0

Set Me.txtbox_TotalTime = "RT: " & txtbox_RT
 

Users who are viewing this thread

Top Bottom