![]() |
Reselect a TextBox
Below is my AfterUpdate code for TextBox12. Part of that code gives me a
message if an incorrect time is entered (like 2845 instead of 1845). Is there any code that I can place after the MsgBox so that the number in TextBox12 will be selected. My goal is to prevent them from moving on until the correct number is entered. Private Sub TextBox12_AfterUpdate() On Error GoTo error TextBox12.Value = Format(Application.Text(Replace(TextBox12.Value, ":", ""), "00\:00"), "hh:mm") If TextBox12.Value "" Then If TextBox11.Value "" Then TextBox13.Value = (TimeValue(TextBox12.Value) - TimeValue(TextBox11.Value)) * 24 TextBox13.Value = Format(TextBox13.Value, "0.0000") TextBox1.Value = CDbl("0" & TextBox13.Value) + CDbl("0" & TextBox23.Value) + CDbl("0" & TextBox33.Value) + CDbl("0" & TextBox43.Value) + CDbl("0" & TextBox53.Value) + CDbl("0" & TextBox63.Value) + CDbl("0" & TextBox14.Value) + CDbl("0" & TextBox24.Value) + CDbl("0" & TextBox34.Value) + CDbl("0" & TextBox44.Value) + CDbl("0" & TextBox54.Value) + CDbl("0" & TextBox64.Value) TextBox1.Text = Format(TextBox1.Text, "0.0000") End If End If 'Test that to see if hours worked exceeds shift length If TextBox12.Value "" Then If TextBox11.Value "" Then TextBox2 = TextBox4 - TextBox1 End If If TextBox2.Value < 0 Then TextBox2.Value = 0 GoTo Finished End If TextBox2 = TextBox4 - TextBox1 TextBox2.Text = Format(TextBox2.Text, "0.0000") End If Finished: If TextBox12.Value = "" Then TextBox13.Value = "" End If If TextBox11.Value = "" Then TextBox13.Value = "" End If End error: MsgBox "please enter only time values" End Sub |
Reselect a TextBox
Place your testing code in a BeforeUpdate event. -- mdmackillop ------------------------------------------------------------------------ mdmackillop's Profile: http://www.thecodecage.com/forumz/member.php?userid=113 View this thread: http://www.thecodecage.com/forumz/sh...ad.php?t=69277 |
Reselect a TextBox
Is there no way to get what I want without changing to the BeforeUpdate. All
I want is for the focus to return to TextBox12. "mdmackillop" wrote in message ... Place your testing code in a BeforeUpdate event. -- mdmackillop ------------------------------------------------------------------------ mdmackillop's Profile: http://www.thecodecage.com/forumz/member.php?userid=113 View this thread: http://www.thecodecage.com/forumz/sh...ad.php?t=69277 |
Reselect a TextBox
It's the simplest way e.g. Private Sub TextBox12_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean) TextBox12.Value = Format(Application.Text(Replace(TextBox12.Value, ":", ""), "00\:00"), "hh:mm") On Error Resume Next test = TimeValue(TextBox12.Text) If Len(test) = 0 Then MsgBox "Enter valid time" TextBox12.Value = "" Cancel = True End If End Sub Private Sub TextBox12_AfterUpdate() MsgBox TimeValue(TextBox12.Value) End Sub -- mdmackillop ------------------------------------------------------------------------ mdmackillop's Profile: http://www.thecodecage.com/forumz/member.php?userid=113 View this thread: http://www.thecodecage.com/forumz/sh...ad.php?t=69277 |
Reselect a TextBox
Ok you convinced me. Here is the code below.
Notice I added: If TextBox11.Value = "" Then GoTo continue just as a way to get out in case one wanted to get out without putting in a time. Is there anyway that if it is not a valid time (and the msgbox is triggered) to have the number in the TextBox be selected so all the user has to do is start entering a number, without having to manually select what is already in the textBox? I tried using TextBox11.SetFocus but that did not work. Private Sub TextBox11_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean) Dim TestDateVariable TestDateVariable = Format(Replace(TextBox11.Value, ":", ""), "00\:00") If TextBox11.Value = "" Then GoTo continue If IsDate(TestDateVariable) Then TextBox11.Value = Format(TestDateVariable, "hh:mm") Else MsgBox "Sorry but that is not a correct time. Please enter a correct time." Cancel = True End If continue: End Sub "mdmackillop" wrote in message ... It's the simplest way e.g. Private Sub TextBox12_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean) TextBox12.Value = Format(Application.Text(Replace(TextBox12.Value, ":", ""), "00\:00"), "hh:mm") On Error Resume Next test = TimeValue(TextBox12.Text) If Len(test) = 0 Then MsgBox "Enter valid time" TextBox12.Value = "" Cancel = True End If End Sub Private Sub TextBox12_AfterUpdate() MsgBox TimeValue(TextBox12.Value) End Sub -- mdmackillop ------------------------------------------------------------------------ mdmackillop's Profile: http://www.thecodecage.com/forumz/member.php?userid=113 View this thread: http://www.thecodecage.com/forumz/sh...ad.php?t=69277 |
Reselect a TextBox
Private Sub TextBox11_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean) Dim TestDateVariable With TextBox11 If .Value = "" Then Exit Sub TestDateVariable = Format(Replace(.Value, ":", ""), "00\:00") If IsDate(TestDateVariable) Then ..Value = Format(TestDateVariable, "hh:mm") Else MsgBox "Sorry but that is not a correct time. Please enter a correct time." Cancel = True ..SelStart = 0 ..SelLength = Len(.Text) End If End With End Sub -- mdmackillop ------------------------------------------------------------------------ mdmackillop's Profile: http://www.thecodecage.com/forumz/member.php?userid=113 View this thread: http://www.thecodecage.com/forumz/sh...ad.php?t=69277 |
Reselect a TextBox
Thanks a lot. The code as written created errors but adding a . in front
of Value=, SelStart and SelLenength lines corrected that. "mdmackillop" wrote in message ... Private Sub TextBox11_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean) Dim TestDateVariable With TextBox11 If .Value = "" Then Exit Sub TestDateVariable = Format(Replace(.Value, ":", ""), "00\:00") If IsDate(TestDateVariable) Then Value = Format(TestDateVariable, "hh:mm") Else MsgBox "Sorry but that is not a correct time. Please enter a correct time." Cancel = True SelStart = 0 SelLength = Len(.Text) End If End With End Sub -- mdmackillop ------------------------------------------------------------------------ mdmackillop's Profile: http://www.thecodecage.com/forumz/member.php?userid=113 View this thread: http://www.thecodecage.com/forumz/sh...ad.php?t=69277 |
Reselect a TextBox
I use the _exit procedure. It also has the Cancel parm.
If you have a cancel button on the userform, you may want to make sure that the ..takefocusonclick property is set to false (either in the _initialize event or manually changing the property). Then if the user enters that textbox, they can still cancel by without having to type in something that looks like a correct number. "Patrick C. Simonds" wrote: Below is my AfterUpdate code for TextBox12. Part of that code gives me a message if an incorrect time is entered (like 2845 instead of 1845). Is there any code that I can place after the MsgBox so that the number in TextBox12 will be selected. My goal is to prevent them from moving on until the correct number is entered. Private Sub TextBox12_AfterUpdate() On Error GoTo error TextBox12.Value = Format(Application.Text(Replace(TextBox12.Value, ":", ""), "00\:00"), "hh:mm") If TextBox12.Value "" Then If TextBox11.Value "" Then TextBox13.Value = (TimeValue(TextBox12.Value) - TimeValue(TextBox11.Value)) * 24 TextBox13.Value = Format(TextBox13.Value, "0.0000") TextBox1.Value = CDbl("0" & TextBox13.Value) + CDbl("0" & TextBox23.Value) + CDbl("0" & TextBox33.Value) + CDbl("0" & TextBox43.Value) + CDbl("0" & TextBox53.Value) + CDbl("0" & TextBox63.Value) + CDbl("0" & TextBox14.Value) + CDbl("0" & TextBox24.Value) + CDbl("0" & TextBox34.Value) + CDbl("0" & TextBox44.Value) + CDbl("0" & TextBox54.Value) + CDbl("0" & TextBox64.Value) TextBox1.Text = Format(TextBox1.Text, "0.0000") End If End If 'Test that to see if hours worked exceeds shift length If TextBox12.Value "" Then If TextBox11.Value "" Then TextBox2 = TextBox4 - TextBox1 End If If TextBox2.Value < 0 Then TextBox2.Value = 0 GoTo Finished End If TextBox2 = TextBox4 - TextBox1 TextBox2.Text = Format(TextBox2.Text, "0.0000") End If Finished: If TextBox12.Value = "" Then TextBox13.Value = "" End If If TextBox11.Value = "" Then TextBox13.Value = "" End If End error: MsgBox "please enter only time values" End Sub -- Dave Peterson |
Reselect a TextBox
Patrick C. Simonds;248441 Wrote: Thanks a lot. The code as written created errors but adding a . in front of Value=, SelStart and SelLenength lines corrected that. Hi Patrick, This is the second time I've been told my "leading dots" are not appearing, although I see them there. What browser are you using? Regards MD -- mdmackillop ------------------------------------------------------------------------ mdmackillop's Profile: http://www.thecodecage.com/forumz/member.php?userid=113 View this thread: http://www.thecodecage.com/forumz/sh...ad.php?t=69277 |
Reselect a TextBox
I am using Outlook Express and the leading dots were not there. I connect OE
directly to news.microsoft.com. Mke F "mdmackillop" wrote in message ... Patrick C. Simonds;248441 Wrote: Thanks a lot. The code as written created errors but adding a . in front of Value=, SelStart and SelLenength lines corrected that. Hi Patrick, This is the second time I've been told my "leading dots" are not appearing, although I see them there. What browser are you using? Regards MD -- mdmackillop ------------------------------------------------------------------------ mdmackillop's Profile: http://www.thecodecage.com/forumz/member.php?userid=113 View this thread: http://www.thecodecage.com/forumz/sh...ad.php?t=69277 |
All times are GMT +1. The time now is 01:16 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com