Reusing Form Code
Are you hiding the first form or unloading it before you show the second form.
If you're hiding the form, I put this code behind the first userform:
Option Explicit
Private Sub CommandButton1_Click()
Me.Hide
frmLocation.Show
Me.Show
End Sub
Private Sub UserForm_Initialize()
Dim iCtr As Long
For iCtr = 1 To 5
Me.ComboBox1.AddItem "A--" & iCtr
Next iCtr
End Sub
Clicking on commandbutton1 would hide that userform and show the second form.
This was the code I used behind the second userform:
Option Explicit
Private Sub UserForm_Initialize()
Dim Pfx As String
Dim iCtr As Long
If frmEmployee.ComboBox1.ListIndex < 0 Then
'nothing selected
Else
Select Case LCase(frmEmployee.ComboBox1.Value)
Case Is = "a--1": Pfx = "A"
Case Is = "a--2": Pfx = "x"
Case Is = "a--3": Pfx = "y"
Case Else
Pfx = "zzz"
End Select
For iCtr = 1 To 4
Me.ComboBox1.AddItem Pfx & "--" & iCtr
Next iCtr
End If
End Sub
As long as the first userform is still loaded (even if it's hidden), I could
qualify my objects with the name of the userform.
===
If you're unloading the first userform, then showing the second userform, maybe
you can use a public variable in a General module to store what you need. Have
the first userform update that public variable. Have the second userform read
(or read and update) that public variable.
DMc2004 wrote:
Hi
I have two forms, let says they are called:
* frmEmployee
* frmLocation
On both of these forms I have two Combo Boxes, one called cboLocation and
another called cboDepartment.
Both of these boxes are populated by code, so if somebody selects London
then the London Departments appears in the cboDepartment, if they select
Belfast another set of options appear.
I would like to place this code into a separate module but how do i
reference two different forms?
Regards
--
Dave Peterson
|