Home |
Search |
Today's Posts |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Thanks. Now I'm facing a different problem.
I was able to prevent the user from no making a valid entry but if I doesn't make and entry at all and want to leave the form without making any changes, which is legit, it won't let close the form because of the cancel event = true Here is what I have '''' Data validation Private Sub txtUnit01_Exit(ByVal Cancel As MSForms.ReturnBoolean) With Me.txtUnit01 If Len(.Text) = 0 Then MsgBox "Please enter a valid unit number in this box" Cancel = True .SetFocus .SelStart = 0 .SelLength = Len(.Text) Else Call Find_Name01Misc End If End With End Sub '''Exit button Private Sub cmdExit_Click() Cancel = False If MsgBox("This action will close the form and any " _ & vbCrLf & "unposted rent will be lost" & vbCrLf & _ "Do you really want to exit? ", vbYesNo + vbCritical) = vbNo Then Exit Sub Else Unload Me Worksheets("dashboard").Activate End If End Sub Thanks againg "LuisE" wrote: I have an UserForm with some TextBoxes which individuals entries Id like to validate before moving to the next Textbox. I want to force the user to make a valid entry (non blank and right format) before moving to the next. Should I place the code in the Form module?? Here is what I have for the first textbox which matches the entry to an existing record Sub Find_The_Name() Set ws = ActiveSheet Set UnitList = ws.Range("a:a") With UnitList Set rFound = .Find(What:=UnitNo, _ After:=Range("A1"), LookIn:=xlValues, _ Lookat:=xlWhole, SearchOrder:=xlByRows, _ SearchDirection:=xlNext, MatchCase:=False) If Not rFound Is Nothing Then x = rFound.Address CurrentTenant = ws.Range(x).Offset(0, 3).Text Else MsgBox "Couldn't find the unit number" CurrentTenant = "" Exit Sub End If End With End Sub Sub Find_Name01() UnitNo = UserForm1.txtUnit01.Text If UnitNo = "" Then MsgBox "Make avalid entry" Else Call Find_The_Name UserForm1.txtName01.Text = CurrentTenant End If End Sub Thank you |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Textbox validation | Excel Discussion (Misc queries) | |||
Textbox keeps moving | Excel Programming | |||
Textbox validation | Excel Programming | |||
textbox validation | Excel Programming | |||
Code for moving textbox | Excel Programming |