Value of Public Variable Not Being Passed

Ark68

Well-known Member
Joined
Mar 23, 2004
Messages
4,564
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I have oBP declared publically as an object.

This code sets it ..
Rich (BB code):
Private Sub tglb_cue_gm_Click()
    With Me
        Set oBP = .tglb_cue_gm
        sRPT = "CUE-GM.docx"
        button_check ' oBP, sRPT
    End With
End Sub

But when it reaches this code to use is it, I get an error (red line) "Object variable or WIth Block variable not set." It appears to be caused because oBP is empty.

Rich (BB code):
Sub button_check()  '(ByVal oBP As Object, sRPT As String)

'oBP = userform toggle button name (from toggle button click event)
'sRPT = report (.docx) filename (from toggle button click event)

    If bpb = 0 Then 'bypass if bypass flag = 1
        With uf4_works 'the userform
            With oBP
                'this allows a previouly created report to be viewed.
                If .BackColor = RGB(0, 153, 211) And .Value = True Then
                    If DocOpen(sRPT) = False Then
                        Set WordApp = CreateObject("word.Application")
                        WordApp.Documents.Open path_name & sRPT
                        WordApp.Visible = True
                        Set WordApp = Nothing
                        .Value = True
                    End If
    ...

Any thought on what needs to be corrected?
 
Last edited:

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
What is oBP declared as?
Where is it declared?
Are both sets of code in the same module?
What is .tglb_cue_gm?
 
Upvote 0
Hi Fluff

oBP is declared as Object
It is declared in a module that triggers with opening of the application basically. I have all my public variables declared at the very start of my project.
No .. they are in different modules.
.tglb_cue_gm is a toggle button on a userform that is open
 
Upvote 0
How exactly is oBP declared?
& is the declaration in a standard module?
 
Upvote 0
STandard module,

Code:
Public oBP As Object, sRPT As String
 
Upvote 0
In that case your code works for me.
From the snippet you've posted this is redundant
Code:
With uf4_works 'the userform
What happens if you add this
Code:
                Debug.Print oBP.Name
To the beginning of the sub
 
Upvote 0
It appears I'm getting the same error. "Object Variable or With Block Variable not set" when it encounters the Debug line.
 
Upvote 0
Is there any other code in the
Code:
Private Sub tglb_cue_gm_Click()
event that you haven't shown?
Also is there any other code in the second sub before the code you posted?
 
Upvote 0
That same error message also appears when you do not properly close out all With, If/Then, or Loop statements.
However, we cannot tell if that what might be going on because you only posted part of your "Sub button_check()" procedure.
If you post the whole thing, we can help verify that.
 
Upvote 0
Found the problem Fluff!!
I had oBP declared twice. Both the same, but enough to cause problems. I would have thought Excel would have used the last declaration it found, and as they were the same, it wouldn't made a difference. Not the case I guess.

Thanks folks for your support!
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,915
Members
452,366
Latest member
TePunaBloke

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