Trouble Highlighting Contents in text box

MikeAngelastro

Registered User.
Local time
Today, 04:53
Joined
Mar 3, 2000
Messages
254
Hi,

I have a form containing a text box. People enter data to it and then tab out of it. I check it and if there is no problem the program does other things. If there is a problem, I alert the user with a message box and return focus to the original text box. I want the entire contents of the text box to be highlighted at this time. However, the cursor just positions itself in front of the first character. My code follows:

Private Sub InvoiceNo_AfterUpdate()
If Not InvoicePosted(Me.Invoice_Number) Then
Do stuff
Else
MsgBox "This invoice has aready been posted. Either unpost it or select another invoice."
Me.InvoiceNo.SetFocus
Me.InvoiceNo.SelStart = 0
Me.InvoiceNo.SelLength = Len(Me.InvoiceNo.text)
End If

I'm using Access 2002. Any ideas?

Thanks,

Mike
 
Then don't use the selstart etc, or do you not have select entire field as the default action?
 
Rich,

Thanks for your reply. The "select entire field" option has been checked in the keyboard section of the options dialogue box. If I tab around the form, the entire field is highlighted; this may be the result of this setting. But when I set the focus using the code, the entire field is not highlighted. The Access help facility examples all precede the SelLength property setting with the SelStart property setting. I tried it with and without the SelStart setting. I also tried the DoCmd.GotoControl command as well to try to simulate tabbing to the control; it did not help. I even tried to set the focus on another control and then back again but that didn't help either.

Could there be something else I need to do that I am not aware of?

Mike
 
You should to validate the entry using the Before Update event.
This way you could invoke the "Cancel" argument of the procedure to stop the control from loosing focus.

Also to select the text in a control use:

Me.InvoiceNo.SelStart = 0
Me.InvoiceNo.SelLength = Len(Me.InvoiceNo)

Loose the .text as that would be the uncommited value.

HTH
RDH
 

Users who are viewing this thread

Back
Top Bottom