skyline666
Programmer
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:
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
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