Link to home
Start Free TrialLog in
Avatar of apoorva_sriv
apoorva_sriv

asked on

How to access the component of one project from another project(URGENT)

When the object of one project is accessed from some different project a run time error comes as follows:

“Object Variable or With block variable not set”

----------------------------------------------------------------------------------------------------------------------------------------------------------------
Sub DisProfile()

Dim obj As VBComponent
If ActiveSheet.Name = "Discount Profile" Then
    For Each obj In Workbooks("APTv3.2.xls").VBProject.VBComponents
        If obj.Name = "frmFlatDiscount" Then
            obj.Designer.Controls.Item("txtDiscount").text = "56"   ‘ Error comes here
            Exit For
        End If
    Next
    Worksheets("Discount Profile").ComboBox84.Value = Worksheets("Discount Profile").Range("A9")
End If
End Sub
----------------------------------------------------------------------------------------------------------------------------------------------------------------
Here I am trying to set text in the textBox of the form frmFlatDiscount
Avatar of sgayatri
sgayatri

You must say
dim obj as new vbcomponent

or
dim obj as vbcomponent
.
.
.
.
set obj = new vbcomponent '' before using the object obj
By saying new you are actually creating an instance of the object called vbcomponent.

Avatar of apoorva_sriv

ASKER

Thanks for the quick response

Now it is giving the error as "ActiveX component can't create object"
at the newly added line:
   set obj = new vbcomponent            ' error comes here
ASKER CERTIFIED SOLUTION
Avatar of sgayatri
sgayatri

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial