OnExit

P

Pat Hughes

I have a form that I can't seem to figure out how to make the tab be
dependant on the choice that is made from a drop down list. I was thinking
it might have to do with OnExit. But I don't know.

Also, this database I am working in has the time in 2 different data boxes.
So to enter 8:35 AM you have to put in the first box 08 then tab to the 2nd
box and enter 35. Is there a way for this to automatically go to the 2nd box
without tabbing so that it is just regular data entry of 0835? I am
wondering also if OnExit is where I need to put something so I can enter the
time without using the tab.

Thanks,
Pat
 
M

Marshall Barton

Pat said:
I have a form that I can't seem to figure out how to make the tab be
dependant on the choice that is made from a drop down list. I was thinking
it might have to do with OnExit. But I don't know.

Also, this database I am working in has the time in 2 different data boxes.
So to enter 8:35 AM you have to put in the first box 08 then tab to the 2nd
box and enter 35. Is there a way for this to automatically go to the 2nd box
without tabbing so that it is just regular data entry of 0835? I am
wondering also if OnExit is where I need to put something so I can enter the
time without using the tab.


You need to describe your situation in more specific terms.
At one point it seems like you are talking about a tab page
on a tab control, but then you use the word tab as if it's
the Tab key.

You should also explain why the time is in two separate text
boxes. This is unusual and it might be necessary, but,
depending on how the hour and minute values are used, could
be either a good or terrible way to do things.
 
P

Pat Hughes

Marchall,
Thanks for your quick response and sorry for the confusion.

The first question. This is a database made by the Illinois Dept. of
Transportation, IDOT, and I'm trying to make the entering of the database
easier. When I am in the form and I answer one of the drop down lists, (for
ex. "Type of Violation" - answer being the list "Moving, Equipment,
License/Registration") when I tab the curser automatically goes to the wrong
place to enter the next data. Changing the tab order doesn't work because
depending on the answer picked the curser has to go to different places. If
"Moving Violation" is picked then it needs to tab to "Type of Moving
Violation" which is another list box. If "Equipment Violation or
License/Registration Violation" it needs to skip "Type of Moving Violation"
and move directly to "Result of Stop". It is also weird that sometimes it
does go to the right place but not consistantly. If I keep entering Moving
Violation tickets it will go to the right place. But as soon as I enter
"Equipment or License/Registration" it goes to a different place and
sometimes back to the beginning of entry at the top of the page.

For the 2nd question, I have no idea why IDOT wrote this form this way for
the time. It doesn't make sense at all to me. But I was wondering if there
was a way I could make it more enter-friendly by just having to type 2314 and
not 23 tab 14.

Just one more question. My IT guy at work is wondering if my changing the
form would change the data we send to IDOT. I said no that the form is
separate from the table the data is in and it wouldn't change anything in the
table where all the data is. Is this correct?

Thanks,
Pat
 
T

Tom Lake

When I am in the form and I answer one of the drop down lists, (for
ex. "Type of Violation" - answer being the list "Moving, Equipment,
License/Registration") when I tab the curser automatically goes to the
wrong
place to enter the next data. Changing the tab order doesn't work
because
depending on the answer picked the curser has to go to different places.
If
"Moving Violation" is picked then it needs to tab to "Type of Moving
Violation" which is another list box. If "Equipment Violation or
License/Registration Violation" it needs to skip "Type of Moving
Violation"
and move directly to "Result of Stop".

In the On Exit event of your Type of Violation control, put code that uses a
Select Case
statement to go to the proper field based on the contents of the Type of
Violation control.
Just one more question. My IT guy at work is wondering if my changing the
form would change the data we send to IDOT. I said no that the form is
separate from the table the data is in and it wouldn't change anything in
the
table where all the data is. Is this correct?

Your "IT guy" should be replaced! You are correct.

Tom Lake
 
P

Pat Hughes

Tom,

I don't know code. What do I put in the OnExit space in the "Reason For
Stop" (not "type of violation" that I previously said) properties box?

I did find that in my properties box for "Reason For Stop" at "On Lost
Focus" [Event Procedure] the following code:

Private Sub ReasonForStop_LostFocus()
If ReasonForStop.Value = 1 Then
TypeOfMovingViolation.Enabled = True
Else
TypeOfMovingViolation = 0
TypeOfMovingViolation.Enabled = False
End If
End Sub

Private Sub ReasonForStop_Changed()
If ReasonForStop.Value = 1 Then
TypeOfMovingViolation.Enabled = True
Else
TypeOfMovingViolation = 0
TypeOfMovingViolation.Enabled = False
End If
End Sub

This is the only thing written in the "Event" tab of the properties box for
"Reason For Stop".



Thanks,
Pat
 
M

Marshall Barton

To tab to different controls you need some code to determine
which control gets the focus. If it is already going to
different controls, you must have some code in there now.
If so, it should be in the combo box's Exit event procedure,
but you might find it in the LostFocus event. I would
expect the code to be something like:

Select Case cboTypeOfViolation
Case "Moving, Equipment, License/Registration"
Me.txtResultOfStop.SetFocus
Case "Moving Violation"
Me.cboTypeOfMovingViolation.SetFocus
End Select

Your form is probably using different names for the controls
so change my guesses to the real names. If the Type of
Violation combo box really has a numeric value from a lookup
table, then change the Case statements to the appropriate
numbers.

If the hour is always entered as two digits (e.g. 03) then
you can "autotab" to the minutes text box using this kind of
code in the hours text box's Change event procedure:
If Len(Me.txtHour) = 2 Then Me.txtMinutes.SetFocus
but I don't like doing that because it doesn't give users a
chance to correct a mistake.

You should review the tab order list to make sure all the
other controls are in a user friendly order.

As far as changing the data when you change the form. It is
unlikely, but you do have to make sure you do not change a
value in a bound control. The changes we've discussed so
far will affect any data, only the navigation from one
control to another.
 
P

Pat Hughes

Marshall,

In my previous reply to Tom's reply I wrote,
< <I don't know code. What do I put in the OnExit space in the "Reason For
Stop" (not "type of violation" that I previously said) properties box?

I did find that in my properties box for "Reason For Stop" at "On Lost
Focus" [Event Procedure] the following code:

Private Sub ReasonForStop_LostFocus()
If ReasonForStop.Value = 1 Then
TypeOfMovingViolation.Enabled = True
Else
TypeOfMovingViolation = 0
TypeOfMovingViolation.Enabled = False
End If
End Sub

Private Sub ReasonForStop_Changed()
If ReasonForStop.Value = 1 Then
TypeOfMovingViolation.Enabled = True
Else
TypeOfMovingViolation = 0
TypeOfMovingViolation.Enabled = False
End If
End Sub

This is the only thing written in the "Event" tab of the properties box for
"Reason For Stop". > >

As far as the time goes. With what you put as the code "If Len(Me.txtHour)
= 2 Then Me.txtMinutes.SetFocus" you said afterwards that I wouldn't be able
to correct a mistake. So if I used that code I wouldn't be able to go back
in the previous record or in the same record and make a correction or both?

Thanks,
Pat


Marshall Barton said:
To tab to different controls you need some code to determine
which control gets the focus. If it is already going to
different controls, you must have some code in there now.
If so, it should be in the combo box's Exit event procedure,
but you might find it in the LostFocus event. I would
expect the code to be something like:

Select Case cboTypeOfViolation
Case "Moving, Equipment, License/Registration"
Me.txtResultOfStop.SetFocus
Case "Moving Violation"
Me.cboTypeOfMovingViolation.SetFocus
End Select

Your form is probably using different names for the controls
so change my guesses to the real names. If the Type of
Violation combo box really has a numeric value from a lookup
table, then change the Case statements to the appropriate
numbers.

If the hour is always entered as two digits (e.g. 03) then
you can "autotab" to the minutes text box using this kind of
code in the hours text box's Change event procedure:
If Len(Me.txtHour) = 2 Then Me.txtMinutes.SetFocus
but I don't like doing that because it doesn't give users a
chance to correct a mistake.

You should review the tab order list to make sure all the
other controls are in a user friendly order.

As far as changing the data when you change the form. It is
unlikely, but you do have to make sure you do not change a
value in a bound control. The changes we've discussed so
far will affect any data, only the navigation from one
control to another.
--
Marsh
MVP [MS Access]


Pat said:
The first question. This is a database made by the Illinois Dept. of
Transportation, IDOT, and I'm trying to make the entering of the database
easier. When I am in the form and I answer one of the drop down lists, (for
ex. "Type of Violation" - answer being the list "Moving, Equipment,
License/Registration") when I tab the curser automatically goes to the wrong
place to enter the next data. Changing the tab order doesn't work because
depending on the answer picked the curser has to go to different places. If
"Moving Violation" is picked then it needs to tab to "Type of Moving
Violation" which is another list box. If "Equipment Violation or
License/Registration Violation" it needs to skip "Type of Moving Violation"
and move directly to "Result of Stop". It is also weird that sometimes it
does go to the right place but not consistantly. If I keep entering Moving
Violation tickets it will go to the right place. But as soon as I enter
"Equipment or License/Registration" it goes to a different place and
sometimes back to the beginning of entry at the top of the page.

For the 2nd question, I have no idea why IDOT wrote this form this way for
the time. It doesn't make sense at all to me. But I was wondering if there
was a way I could make it more enter-friendly by just having to type 2314 and
not 23 tab 14.

Just one more question. My IT guy at work is wondering if my changing the
form would change the data we send to IDOT. I said no that the form is
separate from the table the data is in and it wouldn't change anything in the
table where all the data is. Is this correct?
 
M

Marshall Barton

Apparently the combo box values are numeric. The code for
the LostFocus event doesn't try to shift the focus, instead
it enables/disables the TypeOfMovingViolation control. If
your current code is working, you should see the control
grayed out and the focus skip past it. This is a perfectly
valid approach and more flexible than setting the focus.

The second routine is probably misspelled (should be
ReasonForStop_Change()) and would be incorrect in any case
so you should probably delete it.

I don't see anything wrong with the procedure's logic, but,
as I said before, you should use the Exit event instead of
the LostFocus event. This is not a critical issue and you
may never notice a difference.

At this point, the only reason I can see for the focus going
to the wrong place is because the Tabe Order list is not
arranged properly.

Do you use the ResultOfStop text box regardless of what's
selected in ReasonForStop? If not, more code would be
needed.

Re the hour text box being changed. I was only addressing a
situation where a user enters 18 when they intended to enter
15. Of course they could go back and change it, but they
could not just use the backspace key to get rid of the 8
because they would already be in the minutes text box. Try
it and see what happens.
--
Marsh
MVP [MS Access]


Pat said:
In my previous reply to Tom's reply I wrote,
< <I don't know code. What do I put in the OnExit space in the "Reason For
Stop" (not "type of violation" that I previously said) properties box?

I did find that in my properties box for "Reason For Stop" at "On Lost
Focus" [Event Procedure] the following code:

Private Sub ReasonForStop_LostFocus()
If ReasonForStop.Value = 1 Then
TypeOfMovingViolation.Enabled = True
Else
TypeOfMovingViolation = 0
TypeOfMovingViolation.Enabled = False
End If
End Sub

Private Sub ReasonForStop_Changed()
If ReasonForStop.Value = 1 Then
TypeOfMovingViolation.Enabled = True
Else
TypeOfMovingViolation = 0
TypeOfMovingViolation.Enabled = False
End If
End Sub

This is the only thing written in the "Event" tab of the properties box for
"Reason For Stop". > >

As far as the time goes. With what you put as the code "If Len(Me.txtHour)
= 2 Then Me.txtMinutes.SetFocus" you said afterwards that I wouldn't be able
to correct a mistake. So if I used that code I wouldn't be able to go back
in the previous record or in the same record and make a correction or both?


Marshall Barton said:
To tab to different controls you need some code to determine
which control gets the focus. If it is already going to
different controls, you must have some code in there now.
If so, it should be in the combo box's Exit event procedure,
but you might find it in the LostFocus event. I would
expect the code to be something like:

Select Case cboTypeOfViolation
Case "Moving, Equipment, License/Registration"
Me.txtResultOfStop.SetFocus
Case "Moving Violation"
Me.cboTypeOfMovingViolation.SetFocus
End Select

Your form is probably using different names for the controls
so change my guesses to the real names. If the Type of
Violation combo box really has a numeric value from a lookup
table, then change the Case statements to the appropriate
numbers.

If the hour is always entered as two digits (e.g. 03) then
you can "autotab" to the minutes text box using this kind of
code in the hours text box's Change event procedure:
If Len(Me.txtHour) = 2 Then Me.txtMinutes.SetFocus
but I don't like doing that because it doesn't give users a
chance to correct a mistake.

You should review the tab order list to make sure all the
other controls are in a user friendly order.

As far as changing the data when you change the form. It is
unlikely, but you do have to make sure you do not change a
value in a bound control. The changes we've discussed so
far will affect any data, only the navigation from one
control to another.
 

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