By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,121 Members | 1,706 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,121 IT Pros & Developers. It's quick & easy.

Open Word File using Dir Function

P: n/a
Friends,

I have created a form with a list box that shows all my Word files.
I have then added the following code (found on comp.databases
newsgroup) to the Open event of my form and it works fine:

Private Sub Form_Open(Cancel As Integer)
Dim file As String
Dim files As String
files = ""
file = Dir$("C:\My Document\Letters\*.*")
While Len(file) > 0
files = files & file & ";"
file = Dir$
Wend
List1.RowSource = files
End Sub

What I would now like is to be able to open the selected file by
clicking on it from the listbox. Is this possible?

Thanks.
Nov 12 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
jp***@tin.it (Paolo) wrote in message news:<9f*************************@posting.google.c om>...
Friends,

I have created a form with a list box that shows all my Word files.
I have then added the following code (found on comp.databases
newsgroup) to the Open event of my form and it works fine:

Private Sub Form_Open(Cancel As Integer)
Dim file As String
Dim files As String
files = ""
file = Dir$("C:\My Document\Letters\*.*")
While Len(file) > 0
files = files & file & ";"
file = Dir$
Wend
List1.RowSource = files
End Sub

What I would now like is to be able to open the selected file by
clicking on it from the listbox. Is this possible?

Thanks.


you could put code to automate Word in your double-click event of the
listbox and pass in the itemselected collection... of course, you
could probably also just use the OpenFile API at www.mvps.org/access
Nov 12 '05 #2

P: n/a
jp***@tin.it (Paolo) wrote in message news:<9f*************************@posting.google.c om>...
Friends,

I have created a form with a list box that shows all my Word files.
I have then added the following code (found on comp.databases
newsgroup) to the Open event of my form and it works fine:

Private Sub Form_Open(Cancel As Integer)
Dim file As String
Dim files As String
files = ""
file = Dir$("C:\My Document\Letters\*.*")
While Len(file) > 0
files = files & file & ";"
file = Dir$
Wend
List1.RowSource = files
End Sub

What I would now like is to be able to open the selected file by
clicking on it from the listbox. Is this possible?

Thanks.

Simply add the code to the OnClick event property of the list box so
that it will open MS Word and the specified document. Do you have that
code?
Ted
Nov 12 '05 #3

P: n/a
Thanks Ted,

No I do not have that code and would really appreciate your help.

Thanks.

Ac*******@att.net (AccessDev) wrote in message news:<41**************************@posting.google. com>...
jp***@tin.it (Paolo) wrote in message news:<9f*************************@posting.google.c om>...
Friends,

I have created a form with a list box that shows all my Word files.
I have then added the following code (found on comp.databases
newsgroup) to the Open event of my form and it works fine:

Private Sub Form_Open(Cancel As Integer)
Dim file As String
Dim files As String
files = ""
file = Dir$("C:\My Document\Letters\*.*")
While Len(file) > 0
files = files & file & ";"
file = Dir$
Wend
List1.RowSource = files
End Sub

What I would now like is to be able to open the selected file by
clicking on it from the listbox. Is this possible?

Thanks.

Simply add the code to the OnClick event property of the list box so
that it will open MS Word and the specified document. Do you have that
code?
Ted

Nov 12 '05 #4

P: n/a
Thanks Ted,

No I do not have that code and would appreciate you help.

Thanks.

Ac*******@att.net (AccessDev) wrote in message news:<41**************************@posting.google. com>...
jp***@tin.it (Paolo) wrote in message news:<9f*************************@posting.google.c om>...
Friends,

I have created a form with a list box that shows all my Word files.
I have then added the following code (found on comp.databases
newsgroup) to the Open event of my form and it works fine:

Private Sub Form_Open(Cancel As Integer)
Dim file As String
Dim files As String
files = ""
file = Dir$("C:\My Document\Letters\*.*")
While Len(file) > 0
files = files & file & ";"
file = Dir$
Wend
List1.RowSource = files
End Sub

What I would now like is to be able to open the selected file by
clicking on it from the listbox. Is this possible?

Thanks.

Simply add the code to the OnClick event property of the list box so
that it will open MS Word and the specified document. Do you have that
code?
Ted

Nov 12 '05 #5

P: n/a
You'll probably want the fIsAppRunning() function, and then if Word is
running, just activate it and then use AppWord.Documents.Add(strFile).

http://www.mvps.org/access/api/api0007.htm

see here:
http://www.mvps.org/access/modules/mdl0006.htm

for an example of using the function... (He's using Excel, but the
differences are really minor.)
HTH,
pieter
Nov 12 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.