textbox setfocus and select current contents

R

rcmodelr

I have a VBA application for Excel I use to check load counts from farms in
the plant's run schedule.

The Userform has one multipage form where page 1 gets the Run Date, Farm
Name & Number, then 8 textboxes each, for House Number, Birds/house, Crew
catching the house, Bird Weight, and total weight coming out of the house.

At the bottom of the userform, it shows the projected load net weight, load
count, & number of cages to expect on the last load at the selected catch
count.

Page 2 of the MultiPage breaks down the bird count, load & last load cage
count by crew.

I have it so when the OK button is clicked, it will place the data into a
worksheet, then select page 1 of the multipage, and setfocus on the run date.
( RunDate.Setfocus )

BUT... if the user TABS into the RunDate or any other TextBox, the system
will AUTOMATICALLY select ALL the textboxes current contents so if I type a
letter, it will replace EVERYTHING in the textbox with what I type.

I WANT this to happen when page1 is already shown and the RunDate takes
focus. But using RunDate.Setfocus ONLY places the cursor INTO the RunDate
Textbox where it was last time I tabbed out of the RunDate textbox.

How can I get it to have the RunDate textbox take focus the SAME WAY it does
when it takes focus by TABBING INTO the RunDate textbox? I've tried every
way I could think of including trying ALL the RunDate textbox properties set
in literally EVERY available setting, but no matter HOW the textbox settings
are configured, when the textbox takes focus with the .Setfocus, it will ONLY
place the cursor into the textbox where it was last time, and trying to use
other properties such as .copy won't accomplish this either.

Only way I've found that SOMETIMES (but NOT ALWAYS) works is if I have Page2
showing when I click OK. But even then, ONE time, it will work and setfocus
to the RunDate box on page1 with the RunDate contents highlighted for
overtyping, next 3 or 4 times, it will be JUST LIKE other attempts, just
placing the cursor IN the RunDate textbox but in a way where if I start
typing it just ADDS what I type to what is already in the RunDate textbox.
 
J

Jim Rech

How can I get it to have the RunDate textbox take focus the SAME WAY itwhen it takes focus by TABBING INTO the RunDate textbox?

You might run this code when the text box is selected:

Private Sub TextBox1_Enter()
With TextBox1
.SelStart = 0
.SelLength = 500 ''anything >= to len of text
End With
End Sub
 
R

rcmodelr

Thanks... That's similar to what I found to do what I wanted...

Here's the code I used (found while looking up on Excel Help for another
task I wanted to add to the program...

MultiPage1.Value = 0
RunDate.SelStart = 0
RunDate.SelLength = RunDate.TextLength
RunDate.SetFocus

This way, it selects exactly as many characters as were previously in the
textbox which is what I wanted.

I'll try it this way for a while, and since most of the time, the Month and
Year of the RunDate, I may decide to revise it again so only the DAY portion
of the RunDate gets selected. But I'll most likely leave it ALL selected so
it won't end up confusing anybody else if I decide to let my boss start using
it to calculate the load counts...

About 2 years ago (before I had ever done ANY Excel or VBA programming, he
asked me if I could develope a program for doing this and I told him I was
sure I could develope such a program eventually (after I figure out how to
program in VBA, which took me about 1 week before I had my FIRST VBA program
working FLAWLESSLY. ALL the weighmasters now use it each day to set up the
spreadsheet for the following shift). I think what I have will do what he
wants, but he never made any mention of any type of pay bonus or anything if
I was able to make a program like this, so I might just let him know I got it
done, and show him how well and easily it works, but also let him know that
if he wants to start using it, MONEY TALKS. Since I only get the standard
weighmaster pay (which is almost $1.50/hr LESS than I got with my former job
before DOT's weight limit changes forced me to the weighmaster job. If I'm
going to be expected to do computer programming BESIDES the normal
weighmaster duties, I should get paid something MORE than standard
weighmaster pay.
 
J

Jim Rech

I should get paid something MORE than standard weighmaster pay.

I couldn't agree more.<g> However let's hope the boss reacts well to being
able to see but not have. Could be interesting. Hopefully he sees the
value in what you do and you're able to get your point across without making
him defensive or angry.

--
Jim
| Thanks... That's similar to what I found to do what I wanted...
|
| Here's the code I used (found while looking up on Excel Help for another
| task I wanted to add to the program...
|
| MultiPage1.Value = 0
| RunDate.SelStart = 0
| RunDate.SelLength = RunDate.TextLength
| RunDate.SetFocus
|
| This way, it selects exactly as many characters as were previously in the
| textbox which is what I wanted.
|
| I'll try it this way for a while, and since most of the time, the Month
and
| Year of the RunDate, I may decide to revise it again so only the DAY
portion
| of the RunDate gets selected. But I'll most likely leave it ALL selected
so
| it won't end up confusing anybody else if I decide to let my boss start
using
| it to calculate the load counts...
|
| About 2 years ago (before I had ever done ANY Excel or VBA programming, he
| asked me if I could develope a program for doing this and I told him I was
| sure I could develope such a program eventually (after I figure out how to
| program in VBA, which took me about 1 week before I had my FIRST VBA
program
| working FLAWLESSLY. ALL the weighmasters now use it each day to set up
the
| spreadsheet for the following shift). I think what I have will do what he
| wants, but he never made any mention of any type of pay bonus or anything
if
| I was able to make a program like this, so I might just let him know I got
it
| done, and show him how well and easily it works, but also let him know
that
| if he wants to start using it, MONEY TALKS. Since I only get the standard
| weighmaster pay (which is almost $1.50/hr LESS than I got with my former
job
| before DOT's weight limit changes forced me to the weighmaster job. If
I'm
| going to be expected to do computer programming BESIDES the normal
| weighmaster duties, I should get paid something MORE than standard
| weighmaster pay.
|
| "Jim Rech" wrote:
|
| > >>How can I get it to have the RunDate textbox take focus the SAME WAY
it
| > >>does
| > when it takes focus by TABBING INTO the RunDate textbox?
| >
| > You might run this code when the text box is selected:
| >
| > Private Sub TextBox1_Enter()
| > With TextBox1
| > .SelStart = 0
| > .SelLength = 500 ''anything >= to len of text
| > End With
| > End Sub
| >
| > --
| > Jim
| > | > >I have a VBA application for Excel I use to check load counts from
farms in
| > > the plant's run schedule.
| > >
| > > The Userform has one multipage form where page 1 gets the Run Date,
Farm
| > > Name & Number, then 8 textboxes each, for House Number, Birds/house,
Crew
| > > catching the house, Bird Weight, and total weight coming out of the
house.
| > >
| > > At the bottom of the userform, it shows the projected load net weight,
| > > load
| > > count, & number of cages to expect on the last load at the selected
catch
| > > count.
| > >
| > > Page 2 of the MultiPage breaks down the bird count, load & last load
cage
| > > count by crew.
| > >
| > > I have it so when the OK button is clicked, it will place the data
into a
| > > worksheet, then select page 1 of the multipage, and setfocus on the
run
| > > date.
| > > ( RunDate.Setfocus )
| > >
| > > BUT... if the user TABS into the RunDate or any other TextBox, the
system
| > > will AUTOMATICALLY select ALL the textboxes current contents so if I
type
| > > a
| > > letter, it will replace EVERYTHING in the textbox with what I type.
| > >
| > > I WANT this to happen when page1 is already shown and the RunDate
takes
| > > focus. But using RunDate.Setfocus ONLY places the cursor INTO the
RunDate
| > > Textbox where it was last time I tabbed out of the RunDate textbox.
| > >
| > > How can I get it to have the RunDate textbox take focus the SAME WAY
it
| > > does
| > > when it takes focus by TABBING INTO the RunDate textbox? I've tried
every
| > > way I could think of including trying ALL the RunDate textbox
properties
| > > set
| > > in literally EVERY available setting, but no matter HOW the textbox
| > > settings
| > > are configured, when the textbox takes focus with the .Setfocus, it
will
| > > ONLY
| > > place the cursor into the textbox where it was last time, and trying
to
| > > use
| > > other properties such as .copy won't accomplish this either.
| > >
| > > Only way I've found that SOMETIMES (but NOT ALWAYS) works is if I have
| > > Page2
| > > showing when I click OK. But even then, ONE time, it will work and
| > > setfocus
| > > to the RunDate box on page1 with the RunDate contents highlighted for
| > > overtyping, next 3 or 4 times, it will be JUST LIKE other attempts,
just
| > > placing the cursor IN the RunDate textbox but in a way where if I
start
| > > typing it just ADDS what I type to what is already in the RunDate
textbox.
| >
| >
| >
 

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