|
-
Feb 10th, 2005, 09:31 AM
#1
Thread Starter
Member
Help with Focus/Lost Focus
Here is the code another member gave me.
Private Sub TextBox1_Change()
If Val(TextBox1.Text) < 1 Or Val(TextBox1.Text) > 5 Then
MsgBox "Please enter a number between 1 and 5".
TextBox1.SetFocus
End If
End Sub
That works fine, it limits users from entering values less than one and greater than 5 but if the user simply presses enter or tab the box remains blank.
I have tried several ways to capture this event. Is this a problem with the AutoTab feature?
Thanks.
-
Feb 10th, 2005, 10:02 AM
#2
Frenzied Member
Re: Help with Focus/Lost Focus
Try using the LostFocus event :
Code:
Private Sub Text1_LostFocus()
If Val(Text1) < 1 Or Val(Text1) > 5 Then
MsgBox "Valid Values between 1 and 5 !"
Text1.SetFocus
End If
End Sub
-
Feb 10th, 2005, 10:19 AM
#3
Thread Starter
Member
Re: Help with Focus/Lost Focus
There is no lostfocus event in excel vba.
Is there another way to do this?
-
Feb 10th, 2005, 10:22 AM
#4
Frenzied Member
Re: Help with Focus/Lost Focus
ummm .... I hate to disappoint you but Im afraid there is.
I am presuming you are using a textbox, based on your code above.
-
Feb 10th, 2005, 10:27 AM
#5
Thread Starter
Member
Re: Help with Focus/Lost Focus
I tried to write my own
Private Sub Textbox1_lostfoucs()
and it did not work ... any reasons?
-
Feb 10th, 2005, 10:32 AM
#6
Frenzied Member
Re: Help with Focus/Lost Focus
Ummm ..... you've spelt LostFocus as "lostfoucs"
Just as a matter of interest ..... if you double click your textbox whilst in design mode this takes you to the default "Change" event for a textbox.
If you use the pull-down box in the VBA environment that lists all the events for the textbox can you not see "LostFocus" listed ?
-
Feb 16th, 2005, 09:57 AM
#7
Thread Starter
Member
Re: Help with Focus/Lost Focus
OK... Somethings up. I don't have a mouseover event.
What should I use instead.
I want a label to change color when the mouse is over it.
That is all.'
-
Feb 16th, 2005, 11:22 AM
#8
Re: Help with Focus/Lost Focus
Use the mousemove event.
VB Code:
Private Sub Label1_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
End Sub
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|