Userform question

  • Thread starter Thread starter Brad
  • Start date Start date
B

Brad

How do you select an item on a user form?

This is incorrect - txbFaceAmt.Select

But it would be great if this worked.
 
Unfortunately that didn't work - when I put in

me.facecheck.setfocus - it gave an error
facecheck.setfocus - didn't do anything.

Code
Sub txbFaceAmt_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Call FaceLimitCheck(txbFaceAmt)
End Sub

Sub FaceLimitCheck(Facecheck)
If Not (Facecheck = vbNullString) Then
If Not (IsNumeric(Facecheck)) Then
MsgBox ("Invalid entry please use numbers")
Facecheck.Value = ""
Facecheck.SetFocus
Else
If Facecheck < 25000 Then
MsgBox ("Minimum face amount is 25,000")
Facecheck.Value = ""
Else
Facecheck.Value = Format(Facecheck, "$ #,##0,000")
End If
End If
End If
Call CheckTotalFace
End Sub
 
What is facecheck?

I thought you wanted to set the focus to txbfaceamt?

======
But even simpler would be to change that FaceLimitCheck into a Function that
returns a boolean--if it's ok, then return true

Then you could use:

Sub txbFaceAmt_Exit(ByVal Cancel As MSForms.ReturnBoolean)
dim OkToLeave as boolean
oktoleave = FaceLimitCheck(txbFaceAmt)
if oktoleave = true then
'do nothing
else
cancel = true 'don't leave txbfaceamt
end if
End Sub

This:
if oktoleave = true then
'do nothing
else
cancel = true 'don't leave txbfaceamt
end if

Can be replace with a single line:
cancel = (not oktoleave)
 
I see where you used FaceCheck.

I'd still use the Cancel argument that's built into the _exit procedure.
 
Back
Top