Altering trajectory from a control

V

vr8ce

I have two text controls that are mutually exclusive, i.e. if text is entered
in the first one, the second one should be disabled, and if text is entered
in the second one, the first one should be disabled. I would like to
accomplish this with as little disruption to the user as possible.

I tried putting code in the LostFocus of the first control (as a test) that
disabled the second control if the value of the first was null. However, if
the user puts text in the first control then tabs out, the focus ends up in
never-never land, because apparently LostFocus is too late in the game for
the focus to know to skip the (now) disabled second control.

If I put code in LostFocus to explicitly set focus to the second or third
control (depending on whether the first is empty), then keys that shouldn't
go to those control do anyway. For example, hitting page down in the first
control, which should go to the next row, now goes to the appropriate control
on this page.

What is a (easy?) way to accomplish this? I'm using Access 2003. Thanks!
 
D

Dirk Goldgar

vr8ce said:
I have two text controls that are mutually exclusive, i.e. if text is
entered
in the first one, the second one should be disabled, and if text is
entered
in the second one, the first one should be disabled. I would like to
accomplish this with as little disruption to the user as possible.

I tried putting code in the LostFocus of the first control (as a test)
that
disabled the second control if the value of the first was null. However,
if
the user puts text in the first control then tabs out, the focus ends up
in
never-never land, because apparently LostFocus is too late in the game for
the focus to know to skip the (now) disabled second control.

If I put code in LostFocus to explicitly set focus to the second or third
control (depending on whether the first is empty), then keys that
shouldn't
go to those control do anyway. For example, hitting page down in the first
control, which should go to the next row, now goes to the appropriate
control
on this page.

What is a (easy?) way to accomplish this? I'm using Access 2003. Thanks!


I wouldn't be using LostFocus for this. By the time LostFocus fires, I
think Access has already decided where the focus is going next. From what
you said, each control's AfterUpdate event ought to work. Try this,
substituting the names of your controls for "Text0" and "Text2", as
appropriate:

'------ start of code ------
Private Sub Text0_AfterUpdate()

Me.Text2.Enabled = IsNull(Me.Text0)

End Sub


Private Sub Text2_AfterUpdate()

Me.Text0.Enabled = IsNull(Me.Text2)

End Sub
'------ end of code ------
 
M

Mike Painter

vr8ce said:
I have two text controls that are mutually exclusive, i.e. if text is
entered in the first one, the second one should be disabled, and if
text is entered in the second one, the first one should be disabled.
I would like to accomplish this with as little disruption to the user
as possible.

It would seem to me that the OnChange event would be the place to store the
code.
You will also have to check for the situation when you open the form.

If NZ(me.Thisfield,0) =0 and NZ(me.ThatField,0) = 0 then
'both fields are empty and we are done
Exit sub
else 'one of them has something.
If len(me.Thisfield) > 0 then
me.Thatfield.visible = false
else 'it is the other one
me.Thisfield.visible = false
end if
end if

Either both of the fields are empty after opening or one of thenm is shut
off so the onchange event only needs.

Me.OtherField.visible = False

or

Me.ThisField.visible = false.
 

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