setfocus after a msgbox

  • Thread starter Thread starter simpleMod
  • Start date Start date
S

simpleMod

exit subroutine.... you know what ... i think i am going at this th
wrong way...
i should really check for mouse or key events then validate the entry.

what do you propose?

Thank
 
Yes, I get it there too.

Personally, I avoid the Exit event, too problematical, and better to trap
input, like this

Private Sub BoxWeightTextBox_KeyPress(ByVal KeyAscii As _
MSForms.ReturnInteger)
Select Case True
Case KeyAscii >= Asc("0"): 'OK
Case KeyAscii <= Asc("9"): 'OK
Case ".": 'OK
Case Else: Interaction.Beep
KeyAscii = 0
End Select
End Sub

You can also add bound checking at the end like this

Private Sub BoxWeightTextBox_BeforeUpdate(ByVal Cancel As _
MSForms.ReturnBoolean)
With BoxWeightTextBox
If CDbl(.Text) < 1 Or CDbl(.Text) > 100 Then
MsgBox "Value must be Int between 1 and 100."
.SelStart = 0
.SelLength = Len(.Text)
Cancel = True
End If
End With
End Sub
 

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

Similar Threads


Back
Top