Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Highlight field after msgbox

Status
Not open for further replies.

skyline666

Programmer
Oct 22, 2007
141
GB
Hi,

I have a field called Probability, which can only accept value between and including 1 and 5. I have code that already works for this as below:

Code:
Private Sub Probability_AfterUpdate()

If Me.Probability < 1 Or Me.Probability > 5 Then
MsgBox "Invalid number, must be between and including 1 and 5", vbOKOnly, "Invalid Probability"

Me.Outcome.SetFocus
Me.Probability.SetFocus

'Me.Probability.SelStart = 1
Me.Probability.SelLength = Len(Me.Probability.Text)

End If

End Sub

I have the Me.Outcome.SetFocus line there as if the user did enter 6 for example, the msgbox would appear, but when the user hit OK, the focus went to the next field, so I make it go to that field and then to the required field.

What I would like to do, and have been trying as you can see in the code, is when the user presses OK on the msgbox, then the value that has been entered in the field to be highlighted. I tried this with the .SelLength (and also on that line without the .Text at the end) and tried with the .SelStart, and with both, with no joy. Is there a better way to do this in vba code, or is what I have done wrong?

Also, if that way looks or is correct, and the form is just being a pain as they always are, is there a way to delete the value entered in the cell after the user presses OK?

Many thanks,

Andrew
 
To clear it just use
Code:
Me.Probability = ""
Hope this helps

HarleyQuinn
---------------------------------
The most overlooked advantage to owning a computer is that if they foul up there's no law against wacking them around a little. - Joe Martin

Get the most out of Tek-Tips, read FAQ222-2244 before posting.
 
Thanks harleyquinn that worked, and does the same job as I originally wanted.

Andrew
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top