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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pass control to function from sub 1

Status
Not open for further replies.

bmc1234

Programmer
Jul 21, 2005
50
US
I have a form with an activeX control on it called VintaSoftTwain. I want to pass this control from an event on that form to a function so I can access its methods. My function is defined as follows:

Function scan(vinta1 as VintaSoftTwain)

When I pass the control it gives me a type mismatch error. Does anybody know how to do this properly so I don't get errors? Thanks.
 
I am a little ignorant on this subject, I can get it to work but never fully understand the difference between the active X control and the object itself. hopefully someone smart can explain so we both understand. Most of the properties that you see are properties of the control while some are properties of the object. Here is an example using an active x treeview control
Code:
Private Sub Command0_Click()
  Dim myTVcntrl As Control
  Dim myTVobject As TreeView
  Set myTVcntrl = Me.tvOne
  Set myTVobject = Me.tvOne.Object
  MsgBox getTVcntrlName(myTVcntrl)
  MsgBox getTVobjectNodeCount(myTVobject)
End Sub

Public Function getTVcntrlName(theTV As Control) As String
  getTVcntrlName = theTV.Name
End Function

Public Function getTVobjectNodeCount(theTV As TreeView) As Integer
  getTVobjectNodeCount = theTV.Nodes.Count
End Function
[code]

If I want to get the name of the active X control, I need to use the control itself.  If I pass the treeview object I will get a "method or data member not found" since this is a property of the control and not the tree view object.  In the second function the "nodes" collection is a property of the treeview object and not the control.  


So in your example when you pass vinta1 it should be something like

dim vinta1 as VintaSoftTwain
set vinta1 = me.nameOfControlOnForm.object
scan(vinta1)
 
Why do you need to pass it at all? You should be able to reference it directly from the open form it's on. If it's on the same form as the function, then:

Me.vista1

If it's on a different form (which would have to be open), you can use:

Forms!frmWhatever!vista1



 
How are ya bmc1234 . . .

How are you passing the contrrol (code please)?

Calvin.gif
See Ya! . . . . . .

Be sure to see FAQ219-2884:
 
JoeAtWork,
I disagree. You can reference the container control, but not the Active X object itself as I demonstrated. So even if you do not want to pass in to a function you would need to do something like this assuming vinta1 is the name of the control.

dim vtVinta as VintaSoftTwain
set vtVinta = me.vinta1.object
or if it is on a different form
(set vtVinta = Forms!frmWhatever!vinta1)

You can use the Object property in Visual Basic to return a reference to the ActiveX object that is associated with a linked or embedded OLE object in a control. By using this reference, you can access the properties or invoke the methods of the OLE object.

Remarks
The Object property returns a reference to an ActiveX object. You can use the Set statement to assign this ActiveX object to an object variable. The type of object reference returned depends on which application created the OLE object.

When you embed or link an OLE object in a Microsoft Access form, you can set properties that determine the type of object and the behavior of the container control. However, you can't directly set or read the OLE object's properties or apply its methods, as you can when performing Automation. The Object property returns a reference to an Automation object that represents the linked or embedded OLE object. By using this reference, you can change the OLE object by setting or reading its properties or applying its methods.
 
You can use the Object property in Visual Basic to return a reference to the ActiveX object that is associated with a linked or embedded OLE object in a control.

MajP, I think you are confusing the OP's ActiveX control with a Bound Object Frame. A bound object frame is used to display a document of a program that supports OLE Linking and Embedding. Most typically it is a Word document or Excel spreadsheet. The bound object frame is the container of the OLE object (i.e. the document) and that is what the article you quote is talking about.

But I believe the OP is referring to an actual ActiveX control placed directly on the form (through Insert -> ActiveX Control...). In which case he should be able to access the ActiveX Control's public properties directly in code, just as he could a textbox, button, or combo on the form.

I did a little experiment. I inserted an ActiveX control that I made in VB6 into an Access form I named frmTechSup. I named the control TechSup, and it has a property called UnknownDealerID. I opened that form.

Then in another form, I placed a textbox called txtValue, and a button called cmdShowValue. In the button's click event, I put the following code:
Code:
Private Sub cmdShowValue_Click()
    txtValue = Forms!frmTechSup!TechSup.UnknownDealerID
End Sub
It worked perfectly.


 
MajP,
your solution worked for me. I just passed vinta1.object and it worked like a charm. Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top