Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 130
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 130
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Selecting control on userform with part of control name (set question) Keith Excel Programming 4 January 10th 07 02:24 PM
Control Names Graham Y Excel Programming 2 October 10th 06 04:59 PM
Control Sequence from Userform Control Nigel Excel Programming 3 December 29th 04 01:25 PM
Userform control ZMore Excel Programming 1 March 5th 04 11:34 PM
UserForm Control Richard Choate Excel Programming 0 July 16th 03 06:50 PM


All times are GMT +1. The time now is 12:31 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"