Link to home
Start Free TrialLog in
Avatar of st
st

asked on

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

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.
Avatar of kulikuli
kulikuli

Use a bound object frame or an image control to display it.
To edit/activate the object:
OLE1.Class = "Excel.Sheet" 'Excell example
OLE1.Action = acOLEActiva
Avatar of st

ASKER

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.
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.
Avatar of st

ASKER

This get_document function can't open OLE obj using associate (I need without specify the application to open)
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)


ASKER CERTIFIED SOLUTION
Avatar of kulikuli
kulikuli

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