Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

UserForm to UserForm content of variable

Status
Not open for further replies.

OscarAlberto

Programmer
Dec 4, 2002
15
CR
I am using a Standard Module, Public defined variable, named SourceID, to pass its contents from a UserForm to another UserForm, but it is not working. The code in the first UserForm is the following:

Private Sub OKPrompt_Click()
Call ObjectVarDeclar
Dim Counter As Integer
Application.ScreenUpdating = False

Financing.Activate

.....(code)......

If CheckBox16 = True Then
SourceID = 48
ElseIf CheckBox17 = True Then
SourceID = 49
ElseIf CheckBox18 = True Then
SourceID = 50
End If


The receiving UserForm does not recognize the value of SourceID, assigning a ZERO value to it. The code in the receiving UserForm is the following:


Private Sub UserForm_Initialize()
Call ObjectVarDeclar

UnevenRepayment.BackColor = RGB(0, 128, 64)

If SourceID = 48 Then
TextBox14.Text = "Loan Term Facility #1"
TextBox15.Text = Financing.Range("EquityDrawings").Offset(4, 13)
HorizontalPosition = 13
ColumnNumber = 17
ElseIf SourceID = 49 Then
TextBox14.Text = "Loan Term Facility #2"
TextBox15.Text = Financing.Range("EquityDrawings").Offset(4, 14)
HorizontalPosition = 14
ColumnNumber = 18
ElseIf SourceID = 50 Then
TextBox14.Text = "Loan Term Facility #3"
TextBox15.Text = Financing.Range("EquityDrawings").Offset(4, 15)
HorizontalPosition = 15
ColumnNumber = 19
End If


If Financing.Range(&quot;EquityDrawings&quot;).Offset(4, HorizontalPosition) < 1 Then
TextBox1.BackColor = RGB(0, 0, 255)
TextBox1.TabStop = False
TextBox2.BackColor = RGB(0, 0, 255)
TextBox2.TabStop = False
TextBox3.BackColor = RGB(0, 0, 255)
TextBox3.TabStop = False
TextBox4.BackColor = RGB(0, 0, 255)
TextBox4.TabStop = False
TextBox5.BackColor = RGB(0, 0, 255)
TextBox5.TabStop = False
TextBox6.BackColor = RGB(0, 0, 255)
TextBox6.TabStop = False
TextBox7.BackColor = RGB(0, 0, 255)
TextBox7.TabStop = False
TextBox8.BackColor = RGB(0, 0, 255)
TextBox8.TabStop = False
TextBox9.BackColor = RGB(0, 0, 255)
TextBox9.TabStop = False
TextBox10.BackColor = RGB(0, 0, 255)
TextBox10.TabStop = False
TextBox11.BackColor = RGB(0, 0, 255)
TextBox11.TabStop = False
TextBox12.BackColor = RGB(0, 0, 255)
TextBox12.TabStop = False
TextBox13.BackColor = RGB(0, 0, 255)
TextBox13.TabStop = False

I know the value of SourceID is ZERO because all textboxes appear blue, but the value of Financing.Range(&quot;EquityDrawings&quot;).Offset(4, HorizontalPosition) is 10, so only the last three textboxes should appear blue.

Thanks in advance.

Oscar Alberto.
 
I'm always getting this problem!

Have you tried changing all the &quot;Private&quot;s to &quot;Public&quot;?
That sometimes helps.

Failing that, I'll be following this thread with interest!

 
Not sure, but it may be a timing thing. Try using
Code:
    UserForm_Activate()
instead of
Code:
    UserForm_Initialize()
in your &quot;receiving UserForm.&quot;
 
I tried both suggestions and didn't work.


Keep thinking, and again thank you in advance.
 
There's more going on in your code than you are telling. Here is a very simple demo app with two forms to show how to do what I think you are trying to do.

Create two forms.
Put a text box and a command button on each form.

Set up code this way:
In a code module:
[blue]
Code:
Option Explicit
Public FormToForm As String

Sub demo()
  UserForm1.Show
  UserForm2.Show
End Sub
[/color]

In UserForm1 code page:
[blue]
Code:
Option Explicit

Private Sub UserForm_Initialize()
  TextBox1.Text = &quot;Hello World&quot;
End Sub

Private Sub CommandButton1_Click()
  FormToForm = TextBox1.Text
  Me.Hide
End Sub
[/color]

In UserForm2 code page:
[blue]
Code:
Option Explicit

Private Sub UserForm_Initialize()
  TextBox1.Text = FormToForm
End Sub

Private Sub CommandButton1_Click()
  Me.Hide
End Sub
[/color]

Run the macro (F5) from the code module. You should see the following results:
UserForm1 is initialized with &quot;Hello World&quot; in the text box
Click the button.
&quot;Hello World&quot; is put into the global variable and form1 is closed and form2 is shown.
UserForm2 gets &quot;Hello World&quot; from the global variable and shows the text in the text box.
Click the button.
The form closes and the macro ends.

Any unstability that is introduced will be a result of subsequent changes.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top