PC Review


Reply
Thread Tools Rate Thread

Control names on userform

 
 
=?Utf-8?B?WmFyY2g=?=
Guest
Posts: n/a
 
      8th Nov 2007
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
 
Reply With Quote
 
 
 
 
=?Utf-8?B?TWF0dGhldyBQZmx1Z2Vy?=
Guest
Posts: n/a
 
      8th Nov 2007
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

 
Reply With Quote
 
=?Utf-8?B?WmFyY2g=?=
Guest
Posts: n/a
 
      8th Nov 2007
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

 
Reply With Quote
 
=?Utf-8?B?TWF0dGhldyBQZmx1Z2Vy?=
Guest
Posts: n/a
 
      8th Nov 2007
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 here:

http://www.appspro.com/Utilities/CodeCleaner.htm

HTH,
Matthew Pfluger

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Add Tab names to Userform SLW612 Microsoft Excel Programming 2 14th Feb 2008 10:48 PM
Best Way to Get File Names into UserForm =?Utf-8?B?U3RyYXR1c2Vy?= Microsoft Excel Programming 2 30th Apr 2007 06:40 PM
Selecting control on userform with part of control name (set question) Keith Microsoft Excel Programming 4 10th Jan 2007 02:24 PM
Listing Userform Names =?Utf-8?B?TmlnZWwgUlM=?= Microsoft Excel Programming 9 12th Oct 2006 07:38 AM
How To Get A List Of Names To Appear In A TextBox On A UserForm Minitman Microsoft Excel Programming 0 21st Oct 2004 05:12 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:23 PM.