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

How to open Word and other files and bring the window to the top

Status
Not open for further replies.

Eutychus

Programmer
Nov 14, 2007
61
US
I have some code I found and modified as shown below that opens a Word document. However the window is behind the Access application window that has the button with the code to open the Word application and document. I've searched and so far can't find the code to bring the Word application to be the top window; it is on the task bar. I will need to do the same with Excel files and .pdf files.
Perhaps there is a more generic way to open these file that does not require opening each specific application (like Word). I tried to use ShellExecute but get a compile error; I would prefer ShellExecute if it worked. Perhaps I'm missing a reference library but don't know which one. In any case, the application window needs to be on top. Any help with code examples would be much appreciated! :)

Dim CourseDoc As String
Dim myApp As Object
'Path to the word document
'CourseDoc = "c:\Doc1.doc"
If Len(Me.LinkToCourse & vbNullString) = 0 Then ' Checks for null
MsgBox "Invalid file to open.", vbCritical, "Invalid File"
Else
CourseDoc = Me.LinkToCourse
End If

If Dir(CourseDoc) = "" Then
MsgBox "Document not found."
Else
'Create an instance of MS Word
Set myApp = CreateObject(Class:="Word.Application")
myApp.Visible = True
'Open the Document
myApp.Documents.Open FileName:=CourseDoc
If Not (myApp.ActiveWindow Is Nothing) Then 'only if there's a window
myApp.ActiveWindow.Activate
End If
End If

Thank you!

x
 
I forgot to mention, I'm using Access 2007 on Windows 7 machines. There is a front end on the users' laptops and a backend with the tables holding the data on a server. The Word documents are on the server. Users log onto the domain.
 
A generic way to launch related application:
Application.FollowHyperlink Me.LinkToCourse

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top