Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / August 2005

Tip: Looking for answers? Try searching our database.

yet another setfocus question...

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
TimS - 25 Aug 2005 16:10 GMT
ALL:

I sure hope someone is monitoring the discussion at the moment; as I've
about exhausted myself on this seemingly trivial piece. :-)

UserForm1 includes several textboxes, a combobox, and two command buttons.
TabOrder is set and working fine. The first two controls on the form are
both textboxes [TabIndex(1) and (2)]. There is one disabled control on the
form. It is TextBox2. The simple task I am trying to complete is this:

-the user types text into TextBox1 and tabs out;
-if the text matches one of three possibilities, TextBox2 is enabled and the
focus/cursor moves to it to await user input.
-if the text does not match one of these three possibilities, nothing
happens. TextBox2 remains disabled and is skipped over, with focus passing
to TextBox3.

Originally, my thinking was that I would not need setfocus at all, but that
simply setting enabled to <True> would work. Here is the code:

Private Sub txtCountyWholePetition_Exit(ByVal Cancel As
MSForms.ReturnBoolean)
   Select Case txtCountyWholePetition
       Case "HARRISON", "HINDS", "RANKIN"
           lblJudWholePetition.Enabled = True
           txtJudWholePetition.Enabled = True
   End Select
End Sub

TextBox2 is enabled -- that works. But the focus/cursor is sitting in
TextBox3. The user can BackTab to return to TextBox2, but this isn't the way
it needs to work. I then tried inserting the setfocus command as follows:

Private Sub txtCountyWholePetition_Exit(ByVal Cancel As
MSForms.ReturnBoolean)
   Select Case txtCountyWholePetition
       Case "HARRISON", "HINDS", "RANKIN"
           lblJudWholePetition.Enabled = True
           txtJudWholePetition.Enabled = True
           txtJudWholePetition.setfocus
   End Select
End Sub

What happened then was that the focus skipped TextBox3 as well and jumped to
TextBox4! I then tried moving each of these two code sections to other
events, like beforeupdate, afterupdate, etc...
Then I read on this board where the setfocus command needs to be in the
userform activate event, so I tried that and it didn't work either.

The bottom line is that setfocus just doesn't seem to be doing at all what
it is supposed to be doing. Back in the olden days, when I developed a
handful of FoxPro applications, there was a system variable for the "current
object" called _curobj. I used the snot out of this one -- making the cursor
hop all over the place if needed. For example:

_curobj=objnum("TextBox2")

Sorry for the flashback, but I just wanted to provide an illustration from
my experience. This is probably something very very simple, but this is my
maiden venture with VBA, and showing my ignorance...

Thanks,
Tim
TimS - 25 Aug 2005 17:01 GMT
ALL:

Sorry to be posting a reply to my own message -- and especially so
quickly -- but I just found a solution to the setfocus issue I outlined
above. It turns out my original thinking was correct. I don't need to use
setfocus at all. I simply moved the <Select Case> statement from the _Exit
event to the _Change event. As the user is typing the information into
TextBox1, as soon as it matches one of the three conditional strings,
TextBox2 is enabled. Apparently, this needed to  happen prior to tabbing
out.

Tim

> ALL:
>
[quoted text clipped - 60 lines]
> Thanks,
> Tim
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.