Unable to Maintain Variable Value Between Modules

Ark68

Well-known Member
Joined
Mar 23, 2004
Messages
4,570
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I am trying to open a userform in one workbook from an event in my main code holding workbook.

From a click of an object in workbook1
Code:
Private Sub lb_cntmissp_Click()
    If lb_cntmissp.Caption = "0" Then Exit Sub
    With wb_rd
        Application.Run wb_rd.Name & "!macro_01"
    End With
End Sub
!macro_01 is accessed in workbook2 (wb_rd).

Code:
Public mri As Boolean
Sub macro_01()
    mri = True
    MsgBox "MRI: " & mri
    declarations_1
    'group_1.Show
End Sub

Declarations is a module (in workbook2) where all my worksheets for workbook2 are defined publically, and quite a bit in the application of userform 'group_1'.
MRI is a value used to flag a certain procedure in the initialization of the userform 'group_1'

Code:
Public mbevents As Boolean
Public ws_rd As Worksheet
Public ws_rm As Worksheet
Public ws_amm As Worksheet
Public ws_lists As Worksheet
Public ws_Cust As Worksheet
Public ws_group As Worksheet
Public ws_vh As Worksheet
Public pn As Long
Public CH, df1 As Integer
'Public mri As Boolean

Sub declarations_1()
    Set wb_rd = Workbooks("Rental_Detail.xlsm")
    Set ws_rd = wb_rd.Worksheets("Rental_Data")
    Set ws_rm = wb_rd.Worksheets("Rental_Main")
    Set ws_amm = wb_rd.Worksheets("Ammendments")
    Set ws_lists = wb_rd.Worksheets("LISTS")
    Set ws_Cust = wb_rd.Worksheets("Customer_Default")
    Set ws_group = wb_rd.Worksheets("Group_Defaults")
    Set ws_vh = wb_rd.Worksheets("VAR_HOLD")
    
    group_1.Show
End Sub

The problem I am having, is I'm unable to maintain the value of MRI. In macro_01 it is set to true, but when it reaches the Declarations module, it's false.

What can I do to maintain this variable's value? I though defining it as public would do it. Maybe I'm not declaring it in the right place?
 
Last edited:

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
I switched from using mri as a boolean to mri as long and I seem to have gotten some progress.
 
Upvote 0

Forum statistics

Threads
1,223,894
Messages
6,175,252
Members
452,623
Latest member
Techenthusiast

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top