Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Control names on userform
Hello again :-)
I have a userform on which there are some textboxes which I wish to check whether or not they are blank. I am using a function, and passing the name of the userform into it as FormToCheck. I have inserted the debug.print line in the code while trying to fix my issue. Function CheckForBlanks(FormToCheck) ' Checks form for blank entries Dim Tbx As Control CheckForBlanks = False For Each Tbx In FormToCheck.Controls Debug.Print Tbx.Name If TypeName(Tbx) = "TextBox" Then If Tbx.Text = "" Then ' Check if textbox is empty MsgBox "Please fill in all fields" CheckForBlanks = True Exit Function End If End If Next Tbx End Function The code seems to miss two of the textboxes called tbxChangeFormStartDate and tbxChangeFormEndDate - instead it returns the names as Textbox1 and Textbox2 and considers them as empty even when there is data on the form. If I debug.print tbxChangeFormStartDate.text then I get the value in it! Also I have a SpinButton named SpinButton1 (the default), but this shows as SpinButton2 in the debug.print when the code runs. What have I missed? Are the names for the textboses too long? They are in a frame - could this affect things? Many thanks, Z |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Control names on userform
The fact that the control is in a frame could have some impact. I generally
avoid putting controls in frames whenever possible. I have been burned by them too many times before. Also, have you tried using the .VALUE property instead of .TEXT? I'm not sure, but that also might fix the problem. HTH, Matthew Pfluger "Zarch" wrote: Hello again :-) I have a userform on which there are some textboxes which I wish to check whether or not they are blank. I am using a function, and passing the name of the userform into it as FormToCheck. I have inserted the debug.print line in the code while trying to fix my issue. Function CheckForBlanks(FormToCheck) ' Checks form for blank entries Dim Tbx As Control CheckForBlanks = False For Each Tbx In FormToCheck.Controls Debug.Print Tbx.Name If TypeName(Tbx) = "TextBox" Then If Tbx.Text = "" Then ' Check if textbox is empty MsgBox "Please fill in all fields" CheckForBlanks = True Exit Function End If End If Next Tbx End Function The code seems to miss two of the textboxes called tbxChangeFormStartDate and tbxChangeFormEndDate - instead it returns the names as Textbox1 and Textbox2 and considers them as empty even when there is data on the form. If I debug.print tbxChangeFormStartDate.text then I get the value in it! Also I have a SpinButton named SpinButton1 (the default), but this shows as SpinButton2 in the debug.print when the code runs. What have I missed? Are the names for the textboses too long? They are in a frame - could this affect things? Many thanks, Z |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Control names on userform
Hi Matthew,
Thanks for your reply. Yes I have tried using the .Value property, and also removing the frame. Its strange that the other textboxes are being pikced up correctly. Regards, Z "Matthew Pfluger" wrote: The fact that the control is in a frame could have some impact. I generally avoid putting controls in frames whenever possible. I have been burned by them too many times before. Also, have you tried using the .VALUE property instead of .TEXT? I'm not sure, but that also might fix the problem. HTH, Matthew Pfluger "Zarch" wrote: Hello again :-) I have a userform on which there are some textboxes which I wish to check whether or not they are blank. I am using a function, and passing the name of the userform into it as FormToCheck. I have inserted the debug.print line in the code while trying to fix my issue. Function CheckForBlanks(FormToCheck) ' Checks form for blank entries Dim Tbx As Control CheckForBlanks = False For Each Tbx In FormToCheck.Controls Debug.Print Tbx.Name If TypeName(Tbx) = "TextBox" Then If Tbx.Text = "" Then ' Check if textbox is empty MsgBox "Please fill in all fields" CheckForBlanks = True Exit Function End If End If Next Tbx End Function The code seems to miss two of the textboxes called tbxChangeFormStartDate and tbxChangeFormEndDate - instead it returns the names as Textbox1 and Textbox2 and considers them as empty even when there is data on the form. If I debug.print tbxChangeFormStartDate.text then I get the value in it! Also I have a SpinButton named SpinButton1 (the default), but this shows as SpinButton2 in the debug.print when the code runs. What have I missed? Are the names for the textboses too long? They are in a frame - could this affect things? Many thanks, Z |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Control names on userform
Hmmm. I'm pretty well at a loss myself. I have two final suggestions.
1. Try renaming the controls to shorter names. That may have an impact. 2. Download, install, and run Rob Bovey's Code Cleaner on the file. Sometimes when modules or userforms act strangely, they need to be "cleaned". That is, the file is corrupted and should be exported and imported. Rob's program automates this task. You can find it he http://www.appspro.com/Utilities/CodeCleaner.htm HTH, Matthew Pfluger |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Selecting control on userform with part of control name (set question) | Excel Programming | |||
Control Names | Excel Programming | |||
Control Sequence from Userform Control | Excel Programming | |||
Userform control | Excel Programming | |||
UserForm Control | Excel Programming |