Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Controlling Input
Hi all,
Am all most finished my MedEx XLS and found troubles when trying to delete rows that had a numeric character as the first character (Unsure why). Regardless, I figured that to ensure some protocol, the first character could NOT be a numeric character. The following code works, but it calls the TextBox1_Change() when I attempt to alter its value. This results in the MsgBox appearing twice. Any suggestions to solve this apreciated. TIA Cameron ----------------------------------------------------------- Code: Private Sub TextBox1_Change() If Len(TextBox1.Text) 0 And IsNumeric(VBA.Left(TextBox1.Text, 1)) = False Then If Len(TextBox2.Text) 0 Then If Len(TextBox3.Text) 0 Then ContinueButton.Enabled = True Else ContinueButton.Enabled = False End If Else ContinueButton.Enabled = False End If Else MsgBox "Docors Names generally don't start with numbers.", _ vbOKOnly, "Incorrect Details !!" TextBox1.Text = "" TextBox1.SetFocus ContinueButton.Enabled = False End If End Sub ----------------------------------------------------------- |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Controlling Input
The first occurence of the message box happens when someone enters a number
as the first "character." The second occurence is due to you again changing the text box with the command: TextBox1.Text="" which fires the change event a second time due to Len(TextBox1.Text) not being greater than zero. I changed the code to the following: ------------------------------------ If Len(TextBox1.Text) 0 And IsNumeric(VBA.Left(TextBox1.Text, 1)) = False Then ------------------------------------ If Len(TextBox1.Text) = 0 And IsNumeric(VBA.Left(TextBox1.Text, 1)) = False Then ------------------------------------ HTH -- Michael J. Malinsky Pittsburgh, PA "I am a bear of very little brain, and long words bother me." -- AA Milne, Winne the Pooh "Cameron" wrote in message ... Hi all, Am all most finished my MedEx XLS and found troubles when trying to delete rows that had a numeric character as the first character (Unsure why). Regardless, I figured that to ensure some protocol, the first character could NOT be a numeric character. The following code works, but it calls the TextBox1_Change() when I attempt to alter its value. This results in the MsgBox appearing twice. Any suggestions to solve this apreciated. TIA Cameron ----------------------------------------------------------- Code: Private Sub TextBox1_Change() If Len(TextBox1.Text) 0 And IsNumeric(VBA.Left(TextBox1.Text, 1)) = False Then If Len(TextBox2.Text) 0 Then If Len(TextBox3.Text) 0 Then ContinueButton.Enabled = True Else ContinueButton.Enabled = False End If Else ContinueButton.Enabled = False End If Else MsgBox "Docors Names generally don't start with numbers.", _ vbOKOnly, "Incorrect Details !!" TextBox1.Text = "" TextBox1.SetFocus ContinueButton.Enabled = False End If End Sub ----------------------------------------------------------- |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Controlling Input
You have to set a flag that controls your code. For example:
Dim Working as Boolean Private Sub TextBox1_Change() If Not Working Then If Len(TextBox1.Text) 0 And IsNumeric(Left(TextBox1.Text, 1)) = False Then If Len(TextBox2.Text) 0 Then If Len(TextBox3.Text) 0 Then ContinueButton.Enabled = True Else ContinueButton.Enabled = False End If Else ContinueButton.Enabled = False End If Else Working = True MsgBox "Docors Names generally don't start with numbers.", _ vbOKOnly, "Incorrect Details !!" TextBox1.Text = "" TextBox1.SetFocus ContinueButton.Enabled = False Working = False End If End If End Sub -- Jim Rech Excel MVP |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Controlling Userforms | New Users to Excel | |||
Controlling Sequence | Excel Discussion (Misc queries) | |||
Controlling Tab Oders | Excel Programming | |||
Controlling VBA | Excel Programming | |||
Controlling the mouse | Excel Programming |