Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Multiple User Forms

"Marcotte A" wrote in message
...

1) Can you have multiple userforms in memory at the same time?


Yes

If so, can variables defined or by one form be passed to another (without

a global variable). eg. I will have one form for the user to select a
store; then the next form would have them enter sales data for that store.

You can either access a variable in the calling form from the called form or
vice cersa. In each case, the variable should be declared as a Public
variable within that form

For instnace

in useform1

Userform2.StoreName = Textbox1.Text

in userform2

Public StoreName As String

Private Sub Userform_Initialize()
Me.Textbox1.Text = StoreName
End Sub


2) What is a good way to organize code for forms? I understand that each

form has its own "module", but can code in these call functions and subs
from other userforms or other modules?

Yes, but you need to preceede it with the class name, for instance

Userform2.Macro_To_Do_something


3) Since each store is exactly the same, can I use a tabstrip? How does

VBA differentiate between the tabs? Like this?
Private Sub TabStrip1_Change()
Dim myTab as string
select case tabstrip1.value
case 0: myTab = "Sheet1"
case 1: myTab = "Sheet2"
End Select
With ThisWorkbook.Worksheets(myTab)
'code to input data
End With
End Sub


Not sure what you are tring to do. IF you just want to select which sheet,
radio buttons would be better than tabstrips.

4) What is a good site or book that discusses userforms? I've read the

MS article ("Lesson 11" I think) but am looking for a little bit more than
that.

Pass.


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 593
Default Multiple User Forms

Just to add to what Bob has said...

The most important thing to learn about userforms is that they are
classes, each one being a class in its own right (one class of type
Userform1, another class of type Userform2 etc).

You may have multiple instances of the same class e.g.

Option Explicit

Private m_FormA As UserForm1
Private m_FormB As UserForm1
Private m_FormC As UserForm1

Private Sub Workbook_Open()
Set m_FormA = New UserForm1
m_FormA.Show vbModeless
Set m_FormB = New UserForm1
m_FormB.Show vbModeless
m_FormB.Move _
m_FormA.Left + 20, m_FormA.Top + 20
Set m_FormC = New UserForm1
m_FormC.Show vbModeless
m_FormC.Move _
m_FormB.Left + 20, m_FormB.Top + 20
End Sub

Classes have 'members': properties, methods and events. If you want a
variable defined in an instance of a class to be made available
externally, use a public property e.g.

Option Explicit

Private m_strUsername As String

Public Property Get Username() As String
Username = m_strUsername
End Property

Public Property Let Username(ByVal Newvalue As String)
m_strUsername = Newvalue
End Property

If you want the property to be read-only, omit the Property Let.

I will always advise against using public variables but they are
*particularly* unsuitable for classes because they behave differently
(counterintuitively) from public variables in standard modules. More
details he

http://msdn.microsoft.com/library/de...assmodules.asp

Briefly, using a public variable only saves you writing your own
Property Get/Let pair and thus gives you less flexibility.

A most challenging aspect is how to make one instance of the class
aware of the value of a property in another instance of the same
class.

Where to get a good discussion about userforms? Right here of course!

Jamie.

--
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
user forms Obi-Wan Kenobi Excel Discussion (Misc queries) 0 March 21st 06 08:28 PM
Using multiple user forms to perform Calculations eklarsen[_2_] Excel Programming 1 May 4th 04 03:54 PM
VB user forms Madasu Excel Programming 4 January 11th 04 10:47 PM
User Forms Nev[_2_] Excel Programming 4 October 4th 03 12:35 AM
User forms in VBA Dick Kusleika Excel Programming 0 September 29th 03 05:55 PM


All times are GMT +1. The time now is 01:30 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"