LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default UserForm

Nick,
Yes, declare it the general section so it live as long as the form is loaded
Dim numberOfTextBoxes As Long
Private Sub UserForm_Initialize()
Dim cntrl As Control
For Each cntrl In Me.Controls
If TypeName(cntrl) = "TextBox" And cntrl.Parent Is Frame1 Then
numberOfTextBoxes = numberOfTextBoxes + 1
End If
Next
End Sub

NickHK

"Nick London" wrote in message
...
Thanks! I seem however to have two problems. I thought I knew how to count
the textboxes in a frame but I have a problem with my code:

numberOfTextBoxes = StartPriceFrame.TextBoxes.Count

It simple does not work. Do you perhaps know how to write the code for

this?

The second problem is that I need to use the value for the number of
textboxes in another sub in the userform (e.g. there are five textboxes

i.e.
the number 5). But the varibale numberOfTextBoxes dies after the

initialize
sub. Can you send this variable along or should I declare it is a modular
variable? I would be very thankful if you could help me with this!

"NickHK" skrev:

Nick,
Yes, you would need code like:
Private sub UserForm_Initialize()
'Code Here e.g.
TextBox1.SetFocus
End sub

The _Initialize event is fired when the Userform is first shown and the
_Activate event fires whenever the form receives focus.
Check out the Help for (in English) "Understanding Objects, Properties,
Methods, and Events"

NickHK

"Nick London" wrote in message
...
Thank you. I am however not very accostomed to VB. How do you the
UserForm_Activate() and UserForm_Initialize() ? Do you write:

Private sub UserForm_Activate()
.....count checkboxes
End sub

or how do you use it? Would be very much appreciated with help since I

dont
really know my way around these blocks....

"NickHK" skrev:

The Userform has various events that you can respond to. I would
UserForm_Activate() and UserForm_Initialize() are the ones you are

looking
for.

NickHK

"Nick London" wrote in

message
...
I have I user form that is shown when the user presses a button on

a
spreadsheet.
The code in the spreasheet is:

Public Sub startKnapp_Click()
userForm1.Show
End Sub

Then the userform is shown. I want to do certain things when the

userform
is
opened etc. count number of textboxes. How do you write code so

that
the
program does certain things directly when the userform is opened

i.e.
the
user shall not be forced to press a button or move the cursor over

certain
areas etc.? Please help me if you know how! Thanks!








 
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
Userform to enter values and shown in same userform in list helmekki[_104_] Excel Programming 0 November 19th 05 03:23 PM
Looping procedure calls userform; how to exit loop (via userform button)? KR Excel Programming 6 July 27th 05 12:57 PM
Activating userform and filling it with data form row where userform is activate Marthijn Beusekom via OfficeKB.com[_2_] Excel Programming 3 May 6th 05 05:44 PM
Access from add_in userform to main template userform.... Ajit Excel Programming 1 November 18th 04 05:15 PM
Linking userform to userform in Excel 2003 missmelis01 Excel Programming 2 August 27th 04 08:07 PM


All times are GMT +1. The time now is 08:17 PM.

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

About Us

"It's about Microsoft Excel"