How to set a 'SELECT" prompt in a filed in VBA

We need to set a field as "SELECTED" as we do in VB but in VBA.  The Outlook 2007 VBA doesn't have this property.  

What is the method of setting a field as "SELECTED" in VBA?
Private Sub txtBuyer_GotFocus()
   txtBuyer.SelStart = 0
   txtBuyer.SelLength = Len(txtBuyer.Text)
End Sub

Open in new window

rayluvsAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Chris BottomleySoftware Quality Lead EngineerCommented:
Are you looking for setfocus for example:

Me.Controls("TxtSeller").SetFocus

Chris
0
rayluvsAuthor Commented:
We're looking for that prior the focus entering the field, to have the fields contents selected like if someone highlights it for a copy or cut.
0
Chris BottomleySoftware Quality Lead EngineerCommented:
In that case the code in your initial post is what does the job ... since the event shows the code then teh control should active.

Chris
0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

rayluvsAuthor Commented:
Understood. but the VBA doesn't recognize it.  Already tried it prior placing the question.
0
Chris BottomleySoftware Quality Lead EngineerCommented:
If you are referring to the event then try the change event:

Admittedly on a quick test for me it makes the selection on every text box ... and I cannot understand why - but perhaps it will help where I cannot see any other events that would help.

Chris
Private Sub txtBuyer_Change()
    With Me.txtBuyer
        .SelStart = Len(.Text)
        .SelLength = 0
    End With
End Sub

Open in new window

0
rayluvsAuthor Commented:
Tried the Change, BeforeUpdate, Exit and all events, and doesn't work.  

We're still trying....
0
rayluvsAuthor Commented:
We just saw a very interesting regarding changing the fonts... any suggestions?
0
rayluvsAuthor Commented:
Please view this link... we are trying top understand it... please advice if this could be a solution.

Thanx Lots!

http://msdn.microsoft.com/en-us/library/dd644812(v=office.12).aspx
0
Chris BottomleySoftware Quality Lead EngineerCommented:
Whilst access controls have the got focus event .... in outlook they don't - as far as I can see and as far as a number of web searches go.  The only equivalent is the change as mentioned  - in what way does it not work, have you tried it as shown and is htere any visible effect?

Chris
0
rayluvsAuthor Commented:
I tried it exactly as you have presented in ' ID: 37335829' bur no effect.  Maybe in your test you had m ore than 1 field?  
0
Chris BottomleySoftware Quality Lead EngineerCommented:
Yes I did I assumed buyer and seller in my test.  Bottom line then is no there is no gotfocus on outlook forms and it sounds as if in your case there is no work around.

Chris
0
rayluvsAuthor Commented:
but did it work for you?
0
Chris BottomleySoftware Quality Lead EngineerCommented:
Not with a single field it didn't.

Chris
0
rayluvsAuthor Commented:
So it did work with 2 fields? si so, then we can make an additional field and hide from form?

Please advice
0
Chris BottomleySoftware Quality Lead EngineerCommented:
LOoks like I created a form with two text filelds and an option button.  Placed text in the visible text and tabbed to the option and back again ... text field highlighted

Chris
0
Chris BottomleySoftware Quality Lead EngineerCommented:
Sorry perhaps not clear for me "looks like" is meant to portray "looks like it'll work" and I used the change sub code on the visible text box.

Chris
0
rayluvsAuthor Commented:
didn't understand you last enrty?
0
Chris BottomleySoftware Quality Lead EngineerCommented:
>>> So it did work with 2 fields? si so, then we can make an additional field and hide from form?

Yes, and yes it will.  I created a form with one hidden textbox and one visible one with another control field to tab between.  As long as there is something else on the form for it to tab to of course.

For the case I tested I had one visible textbox, one hidden text box and an option box ... but pretty much any control should do.

Chris
0
rayluvsAuthor Commented:
Ok... will try
0
rayluvsAuthor Commented:
Didn't work.  How exactly did you did it?

0
Chris BottomleySoftware Quality Lead EngineerCommented:
Okay then in outlook created a new form and dragged two textbox fileds onto it, made the one visible = false using the properties and then in the VBE added the single sub as below.  Obviously I did not name it as yours but the same should apply allowing for the name change.

I am using 2010 but I would be most surprised if this was different functionality since I have seen the code mentioned for 2007 outlook elsewhere.

Chris
Private Sub TextBox1_Change()
    If Me.ActiveControl = Me.TextBox1 Then
        With Me.TextBox1
            .SelStart = Len(.Text)
            .SelLength = 0
        End With
    End If
End Sub

Open in new window

0
rayluvsAuthor Commented:
Didnt work and i created a new form.  

Here si a step by step and when we need the Highlieght/Select subroutine be runned:

1. Form as 2 fields
2. User is in filed1
3. User types any character in field1 (at this point we don't want to run the Select or
    Highlight routine)
4. User tabs out of the field1 and control goes to field2 (again, at this point we don't want to
    run the Select or Highlight routine)
5. User tabs back to field1 or clicks con field1 (at this point is when we want to have the field1
    contents look highlighted or select)

Is this the same use your are applying (just want to make sure you have what we want to to)
0
Chris BottomleySoftware Quality Lead EngineerCommented:
That isn't quite as I have it but changed quickly just to prove and yes when you tab between fields the text is highlighted in every case, (as previously mentioned).

It does not do so when clicking the mouse elsewhere i.e. changing the selection by clicking in the textbox but as stated there is no focus change event in outlook VBA.

Chris
0
rayluvsAuthor Commented:
When TABing, it does highlight the field; its a function I guess already built in.  What we need is when user click on the field, as in entering in the field, that will have same effect as when TABing.  #5 should have read:

5. User clicks back to field1  (at this point is when we want to have the field1
    contents look highlighted or select)

In VB, GotFocus works great but VBA the closest is for GotFocus is 'enter'.

In you VBA, when you click on the field, it gets highlighted like when TABing?
0
Chris BottomleySoftware Quality Lead EngineerCommented:
>>> In you VBA, when you click on the field, it gets highlighted like when TABing?

No. like I said highlighting only works when tabbing, there is NO focus event handling built in to outlook VBA forms so clicking in the field does not run any code.

To address the initial selection of the textbox you could for example use the mousedown event to trigger the selection ... but if the user makes some changes, moves the cursor with the mouse then all will again be selected with the potential to delete what was already present.   Again there is no event to address getting the focus so everything is a work around.

Chris
Private Sub txtBuyer_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
        With Me.txtBuyer
            .SelStart = 0
            .SelLength = Len(.Text)
        End With
End Sub

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rayluvsAuthor Commented:
So at the end, there is no way of getting this done?
0
Chris BottomleySoftware Quality Lead EngineerCommented:
Correct there are only work arounds.

Chris
0
rayluvsAuthor Commented:
What I mean is that even the workaround do not work.  Is that correct? (i just want to be sure and close the question)
0
Chris BottomleySoftware Quality Lead EngineerCommented:
If the work around you refer to is the mouse click then perhaps you do not have macros enabled, per ms on http://office.microsoft.com/en-us/outlook-help/enable-or-disable-macros-in-office-documents-HA010031071.aspx?CTT=5&origin=HA010227863#BM13

On the Tools menu, click Trust Center.
Click Macro Settings.
Click the options that you want:
No warnings and disable all macros Click this option if you don't trust macros. All macros and security alerts about macros are disabled.
Warnings for signed macros; all unsigned macros are disabled This is the default setting and is the same as the Disable all macros with notification option, except that if the macro is digitally signed by a trusted publisher, the macro can run if you have already trusted the publisher. If you have not trusted the publisher, you are notified. That way, you can choose to enable those signed macros or trust the publisher. All unsigned macros are disabled without notification.
Warnings for all macros Click this option if you want macros to be disabled, but you want to get security alerts if there are macros present. This way, you can choose when to enable those macros on a case by case basis.
No security check for macros (Not recommended) Click this option to allow all macros to run. This setting makes your computer vulnerable to potentially malicious code and is not recommended.


Chris
0
rayluvsAuthor Commented:
Hi Chris... thanx for the detail info on enabling macros.  However, we do have macros enable; we have a series of VBA scripts that we use every day and almost every moment withing Outlook.

As for the workaround, I mean the scripts that we understand that did work for you.  We're a bit confuse as to it did work or not, seo we ask you:

Which of your recommendations above displayed a field as selected, highlighted or "Tab" into, by just the user clicking on the field (no Tabbing)?

0
Chris BottomleySoftware Quality Lead EngineerCommented:
http:#37340127

Displayed a field with the contents highlighted by just the user clicking on the field (no Tabbing).

Chris
0
rayluvsAuthor Commented:
But its confusing.  In your recent entry, you are not saying "yes" but we assume that its a "yes" becuase you state "Displayed a field with the contents highlighted by just the user clicking on the field (no Tabbing)".  But in you the ID your refer to ID37340127, there you are saying No: "No. like I said highlighting only works when tabbing...".

We just want to know if ID: 37340127 or which entry worked, how can we replicate the same effect in our end.  If it didn't work, we just want to know.
0
Chris BottomleySoftware Quality Lead EngineerCommented:
It's only confusing when you mix and match the posts.  If as implied by the continued requests you are trying to elicit an 'equivalent' then ...http:#37340127 should be considered in isolation.

Displayed a field with the contents highlighted by just the user clicking on the field (no Tabbing).

Other posts were based on other alternatives and statements related to my understanding of your requests at the time.

Chris
0
rayluvsAuthor Commented:
Understood and please excuse our lack of knowledge in not seeing which post has the solution.  Can you please tell us which post does what we want so we can concentrate on that:

  What we want:
 We want X field's contents become highlighted or selected for data entry when a users clicks on the textbox field.  We want the same effect that occurs when a user presses the Tab key to get to the X field.

0
Chris BottomleySoftware Quality Lead EngineerCommented:
The link in the response points you to the post which supports the scenario ... the cursor is located elsewhere then on clicking the textbox 'txtbuyer' with the mouse button any existing text will be highlighted.

Chris
0
rayluvsAuthor Commented:
Understood.  Then the ID 37340127 is the post with the script that works for you.

    Private Sub txtBuyer_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X
                            As Single, ByVal Y As Single)
        With Me.txtBuyer
            .SelStart = 0
            .SelLength = Len(.Text)
        End With
    End Sub

We have incorporated your script to ours and it doesn't work, no effect whatsoever.

Here is what we did:

  1. added a textbox field to the form where we want that effect
  2. we placed a Tab order as the second field after the main field we want the effect to be in
  3. the new textbox was left visible to assure all is ok

After this didn't work, we place the lines in the event "Enter" and still no effect.

Please advice on what we may be missing

Thank you.
0
Chris BottomleySoftware Quality Lead EngineerCommented:
I haven't a clue all I can say is it works for me.  Given you have macros working and the code supplied in place I cannot see any reason for failure.

Chris
0
rayluvsAuthor Commented:
How about if you export your project? Maybe I can compare?
0
rayluvsAuthor Commented:
The problem is here.  I created a new form and it worked excellently.  Let me see what happen and if all OK, will proceed closing the question.

Thank you very much!
0
rayluvsAuthor Commented:
Thanx it Worked Perfectly!!!

I reread your entries and found my error.
0
rayluvsAuthor Commented:
Thanx
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.