Fill a text box

robert693

Registered User.
Local time
Today, 05:49
Joined
Mar 22, 2001
Messages
38
I currently have this code that fills a text box with available days of leave depending on how many years an employee has worked for a company:
Private Sub Form_Current()
'Set the cursor to the first name field
'If Full Time check box is checked, this determines _
'the number of days available to an employee depending on _
'length of service.

Me.FirstName.SetFocus
If (FullTime) Then
If [Years_of_Service] >= 7 Then
Me.DaysAval = 30
Else
If [Years_of_Service] >= 5 Then
Me.DaysAval = 25
Else
Me.DaysAval = 20
End If
End If
End If

End Sub
I would like to be able to fill the text box, if an employee is not full time, with any number manually. I currently cannot. Would I add code asking if the employee is not full time?

[This message has been edited by robert693 (edited 07-18-2001).]
 
What is preventing you from filling in the days manually at this point? Are you getting an error? Here's what I would do:

--------------------------
Private Sub Form_Current()
If (FullTime) Then
If [Years_of_Service] >= 7 Then
Me.DaysAval = 30
ElseIf [Years_of_Service] < 7 >= 5 Then
Me.DaysAval = 25
ElseIf [Years_of_Service] < 5 Then
Me.DaysAval = 20
End If
Me.FirstName.SetFocus
Else
Me.DaysAval.SetFocus
End If
End Sub
--------------------------

This will automatically set the days for you if the employee is Fulltime, if not, it will set the focus on the DaysAval field for manual input.

Instead of just moving the focus, you could also prompt the user with an input box to enter in the number of days available if you wanted by replacing the me.DaysAval.setfocus with an input box call, but I don't think this is necessary.

Hope this works!
jamie
 
The big problem is after entering the number into the text box. If I then scroll to another record and then come back to the non-full time record the days aval text box will default to the number of days for the full time employee that I just scrolled from and not retain the number I put in before I scrolled away.
 
Hmmm... that doesn't sound right. It sounds like you have some other issue happening b/c when I tested the sample code I posted earier, I didn't have that happen.

One thing you could try is to add a step to check if DaysAval is Null and if it is run the code; if not, skip it. This would cause DaysAval to be set ONLY if it was null to begin with, and maybe bypass your current problem. Would that help? Using the code sample I posted, the code would then look like:

--------------------------
Private Sub Form_Current()
If IsNull([DaysAval])Then
If (FullTime) Then
If [Years_of_Service] >= 7 Then
Me.DaysAval = 30
ElseIf [Years_of_Service] < 7 >= 5 Then
Me.DaysAval = 25
ElseIf [Years_of_Service] < 5 Then
Me.DaysAval = 20
End If
Me.FirstName.SetFocus
Else
Me.DaysAval.SetFocus
End If
End If
End Sub
--------------------------

Does that get you any closer? :s

[This message has been edited by jstutz (edited 07-18-2001).]
 

Users who are viewing this thread

Back
Top Bottom