Solved

VBA:How to activate a object in OLE OBJECT field?

Posted on 1998-08-27
7
1,075 Views
Last Modified: 2008-02-01
I used OLE Object field to stored document files (eg. *.DOC, *.WPD, *.PDF, *.BMP), how can I activate the object with its associate in a selected record (just like double click the field in table view)?

e.g.
Table.findfist "ID = " & ObjID
Table("Obj Field").activate       <=== Any method like that?

(Or, any other way to do that like this??)

Thanks.
0
Comment
Question by:st
7 Comments
 
LVL 5

Expert Comment

by:kulikuli
ID: 1960437
Use a bound object frame or an image control to display it.
0
 
LVL 5

Expert Comment

by:kulikuli
ID: 1960438
To edit/activate the object:
OLE1.Class = "Excel.Sheet" 'Excell example
OLE1.Action = acOLEActiva
0
 
LVL 1

Author Comment

by:st
ID: 1960439
Kulikuli, is that the only way to do that? If yes, how to activate that bound object/control in coding?
(Furthermore, how can I create an invisible bound object/control tempoary by coding, and activate the OLE obj? Worth more 50 points for this answer.)

Thanks.
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 3

Expert Comment

by:kaldrich
ID: 1960440
I put the information about the document and the code to open it into a field and did this:

Function Get_Document ()

 
'*********************************************
'*                                           *
'*  Function Get_Document ()                 *
'*                                           *
'*  Opens a specific document based on       *
'*  the user selecting a particular record   *
'*  to view.                                 *
'*                                           *
'*  Written 7/24/98 by K. Aldrich            *
'*                                           *
'*********************************************



 Dim Retval As Integer

 Retval = Shell(Forms![Frm - Display Functions]![File to Run], 3)

End Function

In this case,

Forms![Frm - Display Functions]![File to Run] = "C:\MSOFFICE\WINWORD S:\DOCS\DOCIWANT.DOC"

or something like that.


Hope this helps.
0
 
LVL 1

Author Comment

by:st
ID: 1960441
This get_document function can't open OLE obj using associate (I need without specify the application to open)
0
 
LVL 8

Expert Comment

by:Helicopter
ID: 1960442
Have you tried shellexecute instead?

This example reads a filename from the common dialog and opens the app. I know your set up is a bit different but you might be able to get it to work. If so I'll repost as an answer.

     Put this in a module:

       Declare Function ShellExecute Lib "shell32.dll" Alias _
       "ShellExecuteA" (ByVal Hwnd As Long, ByVal lpOperation _
       As String, ByVal lpFile As String, ByVal lpParameters _
       As String, ByVal lpDirectory As String, ByVal nShowCmd _
       As Long) As Long

       Global Const SW_SHOWNORMAL = 1


       And this in a form:

       Public Function StartDoc(DocName As String)
       On Error GoTo StartDoc_Error
       StartDoc = ShellExecute(Application.hWndAccessApp, "Open", DocName, "", "C:\", 1)
       Exit Function

       StartDoc_Error:
                MsgBox "Error: " & Err & " " & Error
                Exit Function
       End Function

       And call it with:

       Private Sub Command3_Click()
       Dim X
       Dim fname As String
       cd.ShowOpen  'cd is the name of the commondialog control
       fname = cd.FileName
       X = StartDoc(fname)

       End Sub

   Or test it in immediate with

   ShellExecute(Application.hWndAccessApp, "Open", "yourfilename.icx", "", "C:\", 1)


0
 
LVL 5

Accepted Solution

by:
kulikuli earned 50 total points
ID: 1960443
I see my last sentence got cut off. It should be:
OLE1.Action = acOLEActivate

And yes, I think this is the BEST way to do it. You can control what will happen to the OLE object upon user interaction.
You can modify the Action property in run-time. That is, you can specify on which moment the user is able to edit or just view the OLE object.

Creating an OLE control on a form is only available in design view. Use the CreateControl method.
0

Featured Post

Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

Join & Write a Comment

Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now