A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Database Design
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Getting from Access to Word



 
 
Thread Tools Display Modes
  #21  
Old January 7th, 2007, 06:06 PM posted to microsoft.public.access.tablesdbdesign
Susan H. White
external usenet poster
 
Posts: 26
Default Getting from Access to Word

Lewie. You really are a prince. I didn't see your message until just now, and
I will try to duplicate your actions. Meanwhile, I copied and renamed my file
and then deleted the first module we wrote. Then I tried the debug process
you described on the NewTest module. Immediately got the message "Compile
error, variable not defined." The module, incidentally, says at the top
"Option Compare Database" and, next line, "option explicit." Then goes on to
Public Sub newtest(), etc.

Before you waste any more time on this, let me follow your latest idea from
top to bottom and see if I can make that work. Susan

"lewie" wrote:

I started over with a list box that contains one field c:\test.doc
when i selected it it open that doc in word.
this code goes in the click event of the button
Private Sub cmdOpenWordDoc_Click()
'Check to see that there is a document file path associated with the
record
Dim filepath As String
filepath = "c:\test.doc"
If IsNull(filepath) Or filepath = "" Then
MsgBox "Please Ensure There Is A File Path Associated For This
Document", _
vbInformation, "Action Cancelled"
Exit Sub
Else
'Check that the document specified in the file path is actually
there
If (Dir(filepath) = "") Then
MsgBox "Document Does Not Exist In The Specified Location",
_
vbExclamation, "Action Cancelled"
Exit Sub
Else
'Opens document in Word
Call OpenWordDoc(filepath)
End If
End If
End Sub
as u can see the name of the button was cmdOpenWordDoc
then in the module I placed this code:
Sub OpenWordDoc(strDocName As String)
Dim objApp As Object
On Error GoTo ERR1
'Opens the document WHERE FORM1 IS YOUR FORM AND LIST1 IS LISTBOX
NAME
strDocName = Forms!FORM1!List1
Set objApp = CreateObject("Word.Application")
objApp.Visible = True
objApp.Documents.Open strDocName
Exit Sub
ERR1:
MsgBox "ERROR IS" + Err.Description
End Sub
as you can see the name of the list box is list1 and the name of the
form is form1
this doesn't check if the file is missing.
if you have word in your reference this should work.
Lewie
lewie wrote:
OH we will need to get rid of the other code you are not using so you
can make a new db and just put this in or if this is the only code get
rid of the rest and then go to the debug tab and press compile. We
could be getting errors from the other code.
Lewie
lewie wrote:
We haven't hooked up the button yet we will do this in steps.
do you know how to use debug menu? in code window using the
view/menu/debug selection will place the debug menu at the top. and if
you hover over the selection with the writing and the arrow it will say
"step into". when you click it it will step through the code.
so palce the cursor on the call newtest line and start stepping. When
you get to the
Documents.Open FileName:=defaultDir & "TEST.DOC"
line and click it should open the document. Ok.
Lewie
Susan H. White wrote:
Lewie, I created a second module for Public Sub newtest() as you directed.
Again triple checked. Included each line except your"OK this will open a test
document . . ." and "this will run it, etc. . . ." Created a test.doc file in
C drive and tested that by the Run process. Then I created a test.doc
pathway in my list box. Then held my breath and pushed the button and . . . .
nothing! Went back to step through the module and I get right away "Compile
Error, variable not defined." Susan

"lewie" wrote:

Public Sub newtest()


defaultDir = "C:\" 'Options.DefaultFilePath(wdDocumentsPath)
defaultDir = defaultDir '+ "Test.doc"
With Application.FileSearch
.FileName = "Test.doc"
.LookIn = defaultDir
.Execute
If .FoundFiles.Count = 1 Then
Documents.Open FileName:=defaultDir & "TEST.DOC"
Else
MsgBox "Test.doc file was not found"
End If
End With
End Sub
ok this will open a text doc named test.doc in c: drive
Public Function x()
Call newtest
End Function
this will run it
then when this is working all we have to do is assign what is in the
dropdown to these values
put this code in module and step thru it.
using the debug bar.

Lewie
Rick Brandt wrote:
"Susan H. White" wrote in message
...
In a form, I have a listbox based on a table that contains Section,
Subsection, Page and Pathway. What I want to have happen is that selecting
one of the lines in the listbox automatically activates the Pathway so that
the specified document comes up in WORD.

I'm just unable to do this, despite hours of frustration with macros,
coding, etc. Can anyone help?

What code are you using now? I would expect something like...

Application.FollowHyperLink Me.ListBoxName.Column(3)

--
Rick Brandt, Microsoft Access MVP
Email (as appropriate) to...
RBrandt at Hunter dot com




  #22  
Old January 7th, 2007, 07:01 PM posted to microsoft.public.access.tablesdbdesign
Susan H. White
external usenet poster
 
Posts: 26
Default Getting from Access to Word

OK Lewie: I started all over. Created a new database named Lewie with one
form containing a listbox based on one table. Then added the button and put
on that code. Then created a module with that code.

Then back to the form, I pushed the button. Got a Microsoft Word header(!!!)
but the message that This File could not be found, check spelling blah,blah.

So I think we must be very close. I backed out and went the RUN route and
brought up the file without incident. Doublechecked that my table has the
correct filepath and spelling.

I changed two things. One is that I rewrote your line filepath =
"c:\test.doc" to "g:\test.doc" because that's where both Lewie and the file
are.

Another is in your code for the module, I left out your all CAPS WHERE FORM1
IS YOUR FORM AND LIST1 IS LISTBOX NAME. Assumed you were writing that to me
so the line is just 'Opens the document. Is this the problem?

"Susan H. White" wrote:

Lewie. You really are a prince. I didn't see your message until just now, and
I will try to duplicate your actions. Meanwhile, I copied and renamed my file
and then deleted the first module we wrote. Then I tried the debug process
you described on the NewTest module. Immediately got the message "Compile
error, variable not defined." The module, incidentally, says at the top
"Option Compare Database" and, next line, "option explicit." Then goes on to
Public Sub newtest(), etc.

Before you waste any more time on this, let me follow your latest idea from
top to bottom and see if I can make that work. Susan

"lewie" wrote:

I started over with a list box that contains one field c:\test.doc
when i selected it it open that doc in word.
this code goes in the click event of the button
Private Sub cmdOpenWordDoc_Click()
'Check to see that there is a document file path associated with the
record
Dim filepath As String
filepath = "c:\test.doc"
If IsNull(filepath) Or filepath = "" Then
MsgBox "Please Ensure There Is A File Path Associated For This
Document", _
vbInformation, "Action Cancelled"
Exit Sub
Else
'Check that the document specified in the file path is actually
there
If (Dir(filepath) = "") Then
MsgBox "Document Does Not Exist In The Specified Location",
_
vbExclamation, "Action Cancelled"
Exit Sub
Else
'Opens document in Word
Call OpenWordDoc(filepath)
End If
End If
End Sub
as u can see the name of the button was cmdOpenWordDoc
then in the module I placed this code:
Sub OpenWordDoc(strDocName As String)
Dim objApp As Object
On Error GoTo ERR1
'Opens the document WHERE FORM1 IS YOUR FORM AND LIST1 IS LISTBOX
NAME
strDocName = Forms!FORM1!List1
Set objApp = CreateObject("Word.Application")
objApp.Visible = True
objApp.Documents.Open strDocName
Exit Sub
ERR1:
MsgBox "ERROR IS" + Err.Description
End Sub
as you can see the name of the list box is list1 and the name of the
form is form1
this doesn't check if the file is missing.
if you have word in your reference this should work.
Lewie
lewie wrote:
OH we will need to get rid of the other code you are not using so you
can make a new db and just put this in or if this is the only code get
rid of the rest and then go to the debug tab and press compile. We
could be getting errors from the other code.
Lewie
lewie wrote:
We haven't hooked up the button yet we will do this in steps.
do you know how to use debug menu? in code window using the
view/menu/debug selection will place the debug menu at the top. and if
you hover over the selection with the writing and the arrow it will say
"step into". when you click it it will step through the code.
so palce the cursor on the call newtest line and start stepping. When
you get to the
Documents.Open FileName:=defaultDir & "TEST.DOC"
line and click it should open the document. Ok.
Lewie
Susan H. White wrote:
Lewie, I created a second module for Public Sub newtest() as you directed.
Again triple checked. Included each line except your"OK this will open a test
document . . ." and "this will run it, etc. . . ." Created a test.doc file in
C drive and tested that by the Run process. Then I created a test.doc
pathway in my list box. Then held my breath and pushed the button and . . . .
nothing! Went back to step through the module and I get right away "Compile
Error, variable not defined." Susan

"lewie" wrote:

Public Sub newtest()


defaultDir = "C:\" 'Options.DefaultFilePath(wdDocumentsPath)
defaultDir = defaultDir '+ "Test.doc"
With Application.FileSearch
.FileName = "Test.doc"
.LookIn = defaultDir
.Execute
If .FoundFiles.Count = 1 Then
Documents.Open FileName:=defaultDir & "TEST.DOC"
Else
MsgBox "Test.doc file was not found"
End If
End With
End Sub
ok this will open a text doc named test.doc in c: drive
Public Function x()
Call newtest
End Function
this will run it
then when this is working all we have to do is assign what is in the
dropdown to these values
put this code in module and step thru it.
using the debug bar.

Lewie
Rick Brandt wrote:
"Susan H. White" wrote in message
...
In a form, I have a listbox based on a table that contains Section,
Subsection, Page and Pathway. What I want to have happen is that selecting
one of the lines in the listbox automatically activates the Pathway so that
the specified document comes up in WORD.

I'm just unable to do this, despite hours of frustration with macros,
coding, etc. Can anyone help?

What code are you using now? I would expect something like...

Application.FollowHyperLink Me.ListBoxName.Column(3)

--
Rick Brandt, Microsoft Access MVP
Email (as appropriate) to...
RBrandt at Hunter dot com




  #23  
Old January 8th, 2007, 03:31 PM posted to microsoft.public.access.tablesdbdesign
lewie
external usenet poster
 
Posts: 40
Default Getting from Access to Word

So did you step through this one. using debug.
That will give you an idea if it is working correctly. Is the listbox
named list1 and the form named form1?
objApp.Documents.Open strDocName is where the doc should open.
the command button is named cmdOpenWordDoc thus the click event is
Private Sub cmdOpenWordDoc_Click()
If you can step through it it would really help.
I am experimenting with this stuff right now too so it is a learning
experience.
That other stuff i did would work sometimes and not others. I couldn't
figure out if it was being cached or what. Anyway this works every time
for me and i am working on concatonating columns in a list box so you
could have the path in one and the file in the other. I am also messing
with the file dialog box it seems promising.
Lewie
Susan H. White wrote:
OK Lewie: I started all over. Created a new database named Lewie with one
form containing a listbox based on one table. Then added the button and put
on that code. Then created a module with that code.

Then back to the form, I pushed the button. Got a Microsoft Word header(!!!)
but the message that This File could not be found, check spelling blah,blah.

So I think we must be very close. I backed out and went the RUN route and
brought up the file without incident. Doublechecked that my table has the
correct filepath and spelling.

I changed two things. One is that I rewrote your line filepath =
"c:\test.doc" to "g:\test.doc" because that's where both Lewie and the file
are.

Another is in your code for the module, I left out your all CAPS WHERE FORM1
IS YOUR FORM AND LIST1 IS LISTBOX NAME. Assumed you were writing that to me
so the line is just 'Opens the document. Is this the problem?

"Susan H. White" wrote:

Lewie. You really are a prince. I didn't see your message until just now, and
I will try to duplicate your actions. Meanwhile, I copied and renamed my file
and then deleted the first module we wrote. Then I tried the debug process
you described on the NewTest module. Immediately got the message "Compile
error, variable not defined." The module, incidentally, says at the top
"Option Compare Database" and, next line, "option explicit." Then goes on to
Public Sub newtest(), etc.

Before you waste any more time on this, let me follow your latest idea from
top to bottom and see if I can make that work. Susan

"lewie" wrote:

I started over with a list box that contains one field c:\test.doc
when i selected it it open that doc in word.
this code goes in the click event of the button
Private Sub cmdOpenWordDoc_Click()
'Check to see that there is a document file path associated with the
record
Dim filepath As String
filepath = "c:\test.doc"
If IsNull(filepath) Or filepath = "" Then
MsgBox "Please Ensure There Is A File Path Associated For This
Document", _
vbInformation, "Action Cancelled"
Exit Sub
Else
'Check that the document specified in the file path is actually
there
If (Dir(filepath) = "") Then
MsgBox "Document Does Not Exist In The Specified Location",
_
vbExclamation, "Action Cancelled"
Exit Sub
Else
'Opens document in Word
Call OpenWordDoc(filepath)
End If
End If
End Sub
as u can see the name of the button was cmdOpenWordDoc
then in the module I placed this code:
Sub OpenWordDoc(strDocName As String)
Dim objApp As Object
On Error GoTo ERR1
'Opens the document WHERE FORM1 IS YOUR FORM AND LIST1 IS LISTBOX
NAME
strDocName = Forms!FORM1!List1
Set objApp = CreateObject("Word.Application")
objApp.Visible = True
objApp.Documents.Open strDocName
Exit Sub
ERR1:
MsgBox "ERROR IS" + Err.Description
End Sub
as you can see the name of the list box is list1 and the name of the
form is form1
this doesn't check if the file is missing.
if you have word in your reference this should work.
Lewie
lewie wrote:
OH we will need to get rid of the other code you are not using so you
can make a new db and just put this in or if this is the only code get
rid of the rest and then go to the debug tab and press compile. We
could be getting errors from the other code.
Lewie
lewie wrote:
We haven't hooked up the button yet we will do this in steps.
do you know how to use debug menu? in code window using the
view/menu/debug selection will place the debug menu at the top. and if
you hover over the selection with the writing and the arrow it will say
"step into". when you click it it will step through the code.
so palce the cursor on the call newtest line and start stepping. When
you get to the
Documents.Open FileName:=defaultDir & "TEST.DOC"
line and click it should open the document. Ok.
Lewie
Susan H. White wrote:
Lewie, I created a second module for Public Sub newtest() as you directed.
Again triple checked. Included each line except your"OK this will open a test
document . . ." and "this will run it, etc. . . ." Created a test.doc file in
C drive and tested that by the Run process. Then I created a test.doc
pathway in my list box. Then held my breath and pushed the button and . . . .
nothing! Went back to step through the module and I get right away "Compile
Error, variable not defined." Susan

"lewie" wrote:

Public Sub newtest()


defaultDir = "C:\" 'Options.DefaultFilePath(wdDocumentsPath)
defaultDir = defaultDir '+ "Test.doc"
With Application.FileSearch
.FileName = "Test.doc"
.LookIn = defaultDir
.Execute
If .FoundFiles.Count = 1 Then
Documents.Open FileName:=defaultDir & "TEST.DOC"
Else
MsgBox "Test.doc file was not found"
End If
End With
End Sub
ok this will open a text doc named test.doc in c: drive
Public Function x()
Call newtest
End Function
this will run it
then when this is working all we have to do is assign what is in the
dropdown to these values
put this code in module and step thru it.
using the debug bar.

Lewie
Rick Brandt wrote:
"Susan H. White" wrote in message
...
In a form, I have a listbox based on a table that contains Section,
Subsection, Page and Pathway. What I want to have happen is that selecting
one of the lines in the listbox automatically activates the Pathway so that
the specified document comes up in WORD.

I'm just unable to do this, despite hours of frustration with macros,
coding, etc. Can anyone help?

What code are you using now? I would expect something like...

Application.FollowHyperLink Me.ListBoxName.Column(3)

--
Rick Brandt, Microsoft Access MVP
Email (as appropriate) to...
RBrandt at Hunter dot com





  #24  
Old January 9th, 2007, 03:08 PM posted to microsoft.public.access.tablesdbdesign
Susan H. White
external usenet poster
 
Posts: 26
Default Getting from Access to Word

Morning Lewie! Yes, I stepped through. Got down to ojbApp.Documents.Open
strDocName and I get a BLANK Word document, same as before - and same as what
happens now when, at the Form level, I hit the button. I know we told Access
that filepath is G:\test.doc. But do i also need to put G:\test.doc in place
of strDocName? And if so, what about all the other entries in the real Table?
Maybe we need to say that filepath is "filepath" which is the name of the
column heading in my table1??"

"lewie" wrote:

So did you step through this one. using debug.
That will give you an idea if it is working correctly. Is the listbox
named list1 and the form named form1?
objApp.Documents.Open strDocName is where the doc should open.
the command button is named cmdOpenWordDoc thus the click event is
Private Sub cmdOpenWordDoc_Click()
If you can step through it it would really help.
I am experimenting with this stuff right now too so it is a learning
experience.
That other stuff i did would work sometimes and not others. I couldn't
figure out if it was being cached or what. Anyway this works every time
for me and i am working on concatonating columns in a list box so you
could have the path in one and the file in the other. I am also messing
with the file dialog box it seems promising.
Lewie
Susan H. White wrote:
OK Lewie: I started all over. Created a new database named Lewie with one
form containing a listbox based on one table. Then added the button and put
on that code. Then created a module with that code.

Then back to the form, I pushed the button. Got a Microsoft Word header(!!!)
but the message that This File could not be found, check spelling blah,blah.

So I think we must be very close. I backed out and went the RUN route and
brought up the file without incident. Doublechecked that my table has the
correct filepath and spelling.

I changed two things. One is that I rewrote your line filepath =
"c:\test.doc" to "g:\test.doc" because that's where both Lewie and the file
are.

Another is in your code for the module, I left out your all CAPS WHERE FORM1
IS YOUR FORM AND LIST1 IS LISTBOX NAME. Assumed you were writing that to me
so the line is just 'Opens the document. Is this the problem?

"Susan H. White" wrote:

Lewie. You really are a prince. I didn't see your message until just now, and
I will try to duplicate your actions. Meanwhile, I copied and renamed my file
and then deleted the first module we wrote. Then I tried the debug process
you described on the NewTest module. Immediately got the message "Compile
error, variable not defined." The module, incidentally, says at the top
"Option Compare Database" and, next line, "option explicit." Then goes on to
Public Sub newtest(), etc.

Before you waste any more time on this, let me follow your latest idea from
top to bottom and see if I can make that work. Susan

"lewie" wrote:

I started over with a list box that contains one field c:\test.doc
when i selected it it open that doc in word.
this code goes in the click event of the button
Private Sub cmdOpenWordDoc_Click()
'Check to see that there is a document file path associated with the
record
Dim filepath As String
filepath = "c:\test.doc"
If IsNull(filepath) Or filepath = "" Then
MsgBox "Please Ensure There Is A File Path Associated For This
Document", _
vbInformation, "Action Cancelled"
Exit Sub
Else
'Check that the document specified in the file path is actually
there
If (Dir(filepath) = "") Then
MsgBox "Document Does Not Exist In The Specified Location",
_
vbExclamation, "Action Cancelled"
Exit Sub
Else
'Opens document in Word
Call OpenWordDoc(filepath)
End If
End If
End Sub
as u can see the name of the button was cmdOpenWordDoc
then in the module I placed this code:
Sub OpenWordDoc(strDocName As String)
Dim objApp As Object
On Error GoTo ERR1
'Opens the document WHERE FORM1 IS YOUR FORM AND LIST1 IS LISTBOX
NAME
strDocName = Forms!FORM1!List1
Set objApp = CreateObject("Word.Application")
objApp.Visible = True
objApp.Documents.Open strDocName
Exit Sub
ERR1:
MsgBox "ERROR IS" + Err.Description
End Sub
as you can see the name of the list box is list1 and the name of the
form is form1
this doesn't check if the file is missing.
if you have word in your reference this should work.
Lewie
lewie wrote:
OH we will need to get rid of the other code you are not using so you
can make a new db and just put this in or if this is the only code get
rid of the rest and then go to the debug tab and press compile. We
could be getting errors from the other code.
Lewie
lewie wrote:
We haven't hooked up the button yet we will do this in steps.
do you know how to use debug menu? in code window using the
view/menu/debug selection will place the debug menu at the top. and if
you hover over the selection with the writing and the arrow it will say
"step into". when you click it it will step through the code.
so palce the cursor on the call newtest line and start stepping. When
you get to the
Documents.Open FileName:=defaultDir & "TEST.DOC"
line and click it should open the document. Ok.
Lewie
Susan H. White wrote:
Lewie, I created a second module for Public Sub newtest() as you directed.
Again triple checked. Included each line except your"OK this will open a test
document . . ." and "this will run it, etc. . . ." Created a test.doc file in
C drive and tested that by the Run process. Then I created a test.doc
pathway in my list box. Then held my breath and pushed the button and . . . .
nothing! Went back to step through the module and I get right away "Compile
Error, variable not defined." Susan

"lewie" wrote:

Public Sub newtest()


defaultDir = "C:\" 'Options.DefaultFilePath(wdDocumentsPath)
defaultDir = defaultDir '+ "Test.doc"
With Application.FileSearch
.FileName = "Test.doc"
.LookIn = defaultDir
.Execute
If .FoundFiles.Count = 1 Then
Documents.Open FileName:=defaultDir & "TEST.DOC"
Else
MsgBox "Test.doc file was not found"
End If
End With
End Sub
ok this will open a text doc named test.doc in c: drive
Public Function x()
Call newtest
End Function
this will run it
then when this is working all we have to do is assign what is in the
dropdown to these values
put this code in module and step thru it.
using the debug bar.

Lewie
Rick Brandt wrote:
"Susan H. White" wrote in message
...
In a form, I have a listbox based on a table that contains Section,
Subsection, Page and Pathway. What I want to have happen is that selecting
one of the lines in the listbox automatically activates the Pathway so that
the specified document comes up in WORD.

I'm just unable to do this, despite hours of frustration with macros,
coding, etc. Can anyone help?

What code are you using now? I would expect something like...

Application.FollowHyperLink Me.ListBoxName.Column(3)

--
Rick Brandt, Microsoft Access MVP
Email (as appropriate) to...
RBrandt at Hunter dot com






  #25  
Old January 10th, 2007, 10:19 PM posted to microsoft.public.access.tablesdbdesign
lewie
external usenet poster
 
Posts: 40
Default Getting from Access to Word

Put G:\test.doc in the list box and select it.
Lewie
Susan H. White wrote:
Morning Lewie! Yes, I stepped through. Got down to ojbApp.Documents.Open
strDocName and I get a BLANK Word document, same as before - and same as what
happens now when, at the Form level, I hit the button. I know we told Access
that filepath is G:\test.doc. But do i also need to put G:\test.doc in place
of strDocName? And if so, what about all the other entries in the real Table?
Maybe we need to say that filepath is "filepath" which is the name of the
column heading in my table1??"

"lewie" wrote:

So did you step through this one. using debug.
That will give you an idea if it is working correctly. Is the listbox
named list1 and the form named form1?
objApp.Documents.Open strDocName is where the doc should open.
the command button is named cmdOpenWordDoc thus the click event is
Private Sub cmdOpenWordDoc_Click()
If you can step through it it would really help.
I am experimenting with this stuff right now too so it is a learning
experience.
That other stuff i did would work sometimes and not others. I couldn't
figure out if it was being cached or what. Anyway this works every time
for me and i am working on concatonating columns in a list box so you
could have the path in one and the file in the other. I am also messing
with the file dialog box it seems promising.
Lewie
Susan H. White wrote:
OK Lewie: I started all over. Created a new database named Lewie with one
form containing a listbox based on one table. Then added the button and put
on that code. Then created a module with that code.

Then back to the form, I pushed the button. Got a Microsoft Word header(!!!)
but the message that This File could not be found, check spelling blah,blah.

So I think we must be very close. I backed out and went the RUN route and
brought up the file without incident. Doublechecked that my table has the
correct filepath and spelling.

I changed two things. One is that I rewrote your line filepath =
"c:\test.doc" to "g:\test.doc" because that's where both Lewie and the file
are.

Another is in your code for the module, I left out your all CAPS WHERE FORM1
IS YOUR FORM AND LIST1 IS LISTBOX NAME. Assumed you were writing that to me
so the line is just 'Opens the document. Is this the problem?

"Susan H. White" wrote:

Lewie. You really are a prince. I didn't see your message until just now, and
I will try to duplicate your actions. Meanwhile, I copied and renamed my file
and then deleted the first module we wrote. Then I tried the debug process
you described on the NewTest module. Immediately got the message "Compile
error, variable not defined." The module, incidentally, says at the top
"Option Compare Database" and, next line, "option explicit." Then goes on to
Public Sub newtest(), etc.

Before you waste any more time on this, let me follow your latest idea from
top to bottom and see if I can make that work. Susan

"lewie" wrote:

I started over with a list box that contains one field c:\test.doc
when i selected it it open that doc in word.
this code goes in the click event of the button
Private Sub cmdOpenWordDoc_Click()
'Check to see that there is a document file path associated with the
record
Dim filepath As String
filepath = "c:\test.doc"
If IsNull(filepath) Or filepath = "" Then
MsgBox "Please Ensure There Is A File Path Associated For This
Document", _
vbInformation, "Action Cancelled"
Exit Sub
Else
'Check that the document specified in the file path is actually
there
If (Dir(filepath) = "") Then
MsgBox "Document Does Not Exist In The Specified Location",
_
vbExclamation, "Action Cancelled"
Exit Sub
Else
'Opens document in Word
Call OpenWordDoc(filepath)
End If
End If
End Sub
as u can see the name of the button was cmdOpenWordDoc
then in the module I placed this code:
Sub OpenWordDoc(strDocName As String)
Dim objApp As Object
On Error GoTo ERR1
'Opens the document WHERE FORM1 IS YOUR FORM AND LIST1 IS LISTBOX
NAME
strDocName = Forms!FORM1!List1
Set objApp = CreateObject("Word.Application")
objApp.Visible = True
objApp.Documents.Open strDocName
Exit Sub
ERR1:
MsgBox "ERROR IS" + Err.Description
End Sub
as you can see the name of the list box is list1 and the name of the
form is form1
this doesn't check if the file is missing.
if you have word in your reference this should work.
Lewie
lewie wrote:
OH we will need to get rid of the other code you are not using so you
can make a new db and just put this in or if this is the only code get
rid of the rest and then go to the debug tab and press compile. We
could be getting errors from the other code.
Lewie
lewie wrote:
We haven't hooked up the button yet we will do this in steps.
do you know how to use debug menu? in code window using the
view/menu/debug selection will place the debug menu at the top. and if
you hover over the selection with the writing and the arrow it will say
"step into". when you click it it will step through the code.
so palce the cursor on the call newtest line and start stepping. When
you get to the
Documents.Open FileName:=defaultDir & "TEST.DOC"
line and click it should open the document. Ok.
Lewie
Susan H. White wrote:
Lewie, I created a second module for Public Sub newtest() as you directed.
Again triple checked. Included each line except your"OK this will open a test
document . . ." and "this will run it, etc. . . ." Created a test.doc file in
C drive and tested that by the Run process. Then I created a test.doc
pathway in my list box. Then held my breath and pushed the button and . . . .
nothing! Went back to step through the module and I get right away "Compile
Error, variable not defined." Susan

"lewie" wrote:

Public Sub newtest()


defaultDir = "C:\" 'Options.DefaultFilePath(wdDocumentsPath)
defaultDir = defaultDir '+ "Test.doc"
With Application.FileSearch
.FileName = "Test.doc"
.LookIn = defaultDir
.Execute
If .FoundFiles.Count = 1 Then
Documents.Open FileName:=defaultDir & "TEST.DOC"
Else
MsgBox "Test.doc file was not found"
End If
End With
End Sub
ok this will open a text doc named test.doc in c: drive
Public Function x()
Call newtest
End Function
this will run it
then when this is working all we have to do is assign what is in the
dropdown to these values
put this code in module and step thru it.
using the debug bar.

Lewie
Rick Brandt wrote:
"Susan H. White" wrote in message
...
In a form, I have a listbox based on a table that contains Section,
Subsection, Page and Pathway. What I want to have happen is that selecting
one of the lines in the listbox automatically activates the Pathway so that
the specified document comes up in WORD.

I'm just unable to do this, despite hours of frustration with macros,
coding, etc. Can anyone help?

What code are you using now? I would expect something like...

Application.FollowHyperLink Me.ListBoxName.Column(3)

--
Rick Brandt, Microsoft Access MVP
Email (as appropriate) to...
RBrandt at Hunter dot com







  #26  
Old January 11th, 2007, 10:56 AM posted to microsoft.public.access.tablesdbdesign
Susan H. White
external usenet poster
 
Posts: 26
Default Getting from Access to Word

There are three records in the box, one of which is the test.doc. I've
selected it and then pushed the button and get the blank Word document. Ditto
when I step through the code. Susan

"lewie" wrote:

Put G:\test.doc in the list box and select it.
Lewie
Susan H. White wrote:
Morning Lewie! Yes, I stepped through. Got down to ojbApp.Documents.Open
strDocName and I get a BLANK Word document, same as before - and same as what
happens now when, at the Form level, I hit the button. I know we told Access
that filepath is G:\test.doc. But do i also need to put G:\test.doc in place
of strDocName? And if so, what about all the other entries in the real Table?
Maybe we need to say that filepath is "filepath" which is the name of the
column heading in my table1??"

"lewie" wrote:

So did you step through this one. using debug.
That will give you an idea if it is working correctly. Is the listbox
named list1 and the form named form1?
objApp.Documents.Open strDocName is where the doc should open.
the command button is named cmdOpenWordDoc thus the click event is
Private Sub cmdOpenWordDoc_Click()
If you can step through it it would really help.
I am experimenting with this stuff right now too so it is a learning
experience.
That other stuff i did would work sometimes and not others. I couldn't
figure out if it was being cached or what. Anyway this works every time
for me and i am working on concatonating columns in a list box so you
could have the path in one and the file in the other. I am also messing
with the file dialog box it seems promising.
Lewie
Susan H. White wrote:
OK Lewie: I started all over. Created a new database named Lewie with one
form containing a listbox based on one table. Then added the button and put
on that code. Then created a module with that code.

Then back to the form, I pushed the button. Got a Microsoft Word header(!!!)
but the message that This File could not be found, check spelling blah,blah.

So I think we must be very close. I backed out and went the RUN route and
brought up the file without incident. Doublechecked that my table has the
correct filepath and spelling.

I changed two things. One is that I rewrote your line filepath =
"c:\test.doc" to "g:\test.doc" because that's where both Lewie and the file
are.

Another is in your code for the module, I left out your all CAPS WHERE FORM1
IS YOUR FORM AND LIST1 IS LISTBOX NAME. Assumed you were writing that to me
so the line is just 'Opens the document. Is this the problem?

"Susan H. White" wrote:

Lewie. You really are a prince. I didn't see your message until just now, and
I will try to duplicate your actions. Meanwhile, I copied and renamed my file
and then deleted the first module we wrote. Then I tried the debug process
you described on the NewTest module. Immediately got the message "Compile
error, variable not defined." The module, incidentally, says at the top
"Option Compare Database" and, next line, "option explicit." Then goes on to
Public Sub newtest(), etc.

Before you waste any more time on this, let me follow your latest idea from
top to bottom and see if I can make that work. Susan

"lewie" wrote:

I started over with a list box that contains one field c:\test.doc
when i selected it it open that doc in word.
this code goes in the click event of the button
Private Sub cmdOpenWordDoc_Click()
'Check to see that there is a document file path associated with the
record
Dim filepath As String
filepath = "c:\test.doc"
If IsNull(filepath) Or filepath = "" Then
MsgBox "Please Ensure There Is A File Path Associated For This
Document", _
vbInformation, "Action Cancelled"
Exit Sub
Else
'Check that the document specified in the file path is actually
there
If (Dir(filepath) = "") Then
MsgBox "Document Does Not Exist In The Specified Location",
_
vbExclamation, "Action Cancelled"
Exit Sub
Else
'Opens document in Word
Call OpenWordDoc(filepath)
End If
End If
End Sub
as u can see the name of the button was cmdOpenWordDoc
then in the module I placed this code:
Sub OpenWordDoc(strDocName As String)
Dim objApp As Object
On Error GoTo ERR1
'Opens the document WHERE FORM1 IS YOUR FORM AND LIST1 IS LISTBOX
NAME
strDocName = Forms!FORM1!List1
Set objApp = CreateObject("Word.Application")
objApp.Visible = True
objApp.Documents.Open strDocName
Exit Sub
ERR1:
MsgBox "ERROR IS" + Err.Description
End Sub
as you can see the name of the list box is list1 and the name of the
form is form1
this doesn't check if the file is missing.
if you have word in your reference this should work.
Lewie
lewie wrote:
OH we will need to get rid of the other code you are not using so you
can make a new db and just put this in or if this is the only code get
rid of the rest and then go to the debug tab and press compile. We
could be getting errors from the other code.
Lewie
lewie wrote:
We haven't hooked up the button yet we will do this in steps.
do you know how to use debug menu? in code window using the
view/menu/debug selection will place the debug menu at the top. and if
you hover over the selection with the writing and the arrow it will say
"step into". when you click it it will step through the code.
so palce the cursor on the call newtest line and start stepping. When
you get to the
Documents.Open FileName:=defaultDir & "TEST.DOC"
line and click it should open the document. Ok.
Lewie
Susan H. White wrote:
Lewie, I created a second module for Public Sub newtest() as you directed.
Again triple checked. Included each line except your"OK this will open a test
document . . ." and "this will run it, etc. . . ." Created a test.doc file in
C drive and tested that by the Run process. Then I created a test.doc
pathway in my list box. Then held my breath and pushed the button and . . . .
nothing! Went back to step through the module and I get right away "Compile
Error, variable not defined." Susan

"lewie" wrote:

Public Sub newtest()


defaultDir = "C:\" 'Options.DefaultFilePath(wdDocumentsPath)
defaultDir = defaultDir '+ "Test.doc"
With Application.FileSearch
.FileName = "Test.doc"
.LookIn = defaultDir
.Execute
If .FoundFiles.Count = 1 Then
Documents.Open FileName:=defaultDir & "TEST.DOC"
Else
MsgBox "Test.doc file was not found"
End If
End With
End Sub
ok this will open a text doc named test.doc in c: drive
Public Function x()
Call newtest
End Function
this will run it
then when this is working all we have to do is assign what is in the
dropdown to these values
put this code in module and step thru it.
using the debug bar.

Lewie
Rick Brandt wrote:
"Susan H. White" wrote in message
...
In a form, I have a listbox based on a table that contains Section,
Subsection, Page and Pathway. What I want to have happen is that selecting
one of the lines in the listbox automatically activates the Pathway so that
the specified document comes up in WORD.

I'm just unable to do this, despite hours of frustration with macros,
coding, etc. Can anyone help?

What code are you using now? I would expect something like...

Application.FollowHyperLink Me.ListBoxName.Column(3)

--
Rick Brandt, Microsoft Access MVP
Email (as appropriate) to...
RBrandt at Hunter dot com








  #27  
Old January 11th, 2007, 03:24 PM posted to microsoft.public.access.tablesdbdesign
lewie
external usenet poster
 
Posts: 40
Default Getting from Access to Word

My answer from yesterday didn't post hmmmm.
Ya you have to put g:\test.doc in the list box and select it.
Lewie
Susan H. White wrote:
Morning Lewie! Yes, I stepped through. Got down to ojbApp.Documents.Open
strDocName and I get a BLANK Word document, same as before - and same as what
happens now when, at the Form level, I hit the button. I know we told Access
that filepath is G:\test.doc. But do i also need to put G:\test.doc in place
of strDocName? And if so, what about all the other entries in the real Table?
Maybe we need to say that filepath is "filepath" which is the name of the
column heading in my table1??"

"lewie" wrote:

So did you step through this one. using debug.
That will give you an idea if it is working correctly. Is the listbox
named list1 and the form named form1?
objApp.Documents.Open strDocName is where the doc should open.
the command button is named cmdOpenWordDoc thus the click event is
Private Sub cmdOpenWordDoc_Click()
If you can step through it it would really help.
I am experimenting with this stuff right now too so it is a learning
experience.
That other stuff i did would work sometimes and not others. I couldn't
figure out if it was being cached or what. Anyway this works every time
for me and i am working on concatonating columns in a list box so you
could have the path in one and the file in the other. I am also messing
with the file dialog box it seems promising.
Lewie
Susan H. White wrote:
OK Lewie: I started all over. Created a new database named Lewie with one
form containing a listbox based on one table. Then added the button and put
on that code. Then created a module with that code.

Then back to the form, I pushed the button. Got a Microsoft Word header(!!!)
but the message that This File could not be found, check spelling blah,blah.

So I think we must be very close. I backed out and went the RUN route and
brought up the file without incident. Doublechecked that my table has the
correct filepath and spelling.

I changed two things. One is that I rewrote your line filepath =
"c:\test.doc" to "g:\test.doc" because that's where both Lewie and the file
are.

Another is in your code for the module, I left out your all CAPS WHERE FORM1
IS YOUR FORM AND LIST1 IS LISTBOX NAME. Assumed you were writing that to me
so the line is just 'Opens the document. Is this the problem?

"Susan H. White" wrote:

Lewie. You really are a prince. I didn't see your message until just now, and
I will try to duplicate your actions. Meanwhile, I copied and renamed my file
and then deleted the first module we wrote. Then I tried the debug process
you described on the NewTest module. Immediately got the message "Compile
error, variable not defined." The module, incidentally, says at the top
"Option Compare Database" and, next line, "option explicit." Then goes on to
Public Sub newtest(), etc.

Before you waste any more time on this, let me follow your latest idea from
top to bottom and see if I can make that work. Susan

"lewie" wrote:

I started over with a list box that contains one field c:\test.doc
when i selected it it open that doc in word.
this code goes in the click event of the button
Private Sub cmdOpenWordDoc_Click()
'Check to see that there is a document file path associated with the
record
Dim filepath As String
filepath = "c:\test.doc"
If IsNull(filepath) Or filepath = "" Then
MsgBox "Please Ensure There Is A File Path Associated For This
Document", _
vbInformation, "Action Cancelled"
Exit Sub
Else
'Check that the document specified in the file path is actually
there
If (Dir(filepath) = "") Then
MsgBox "Document Does Not Exist In The Specified Location",
_
vbExclamation, "Action Cancelled"
Exit Sub
Else
'Opens document in Word
Call OpenWordDoc(filepath)
End If
End If
End Sub
as u can see the name of the button was cmdOpenWordDoc
then in the module I placed this code:
Sub OpenWordDoc(strDocName As String)
Dim objApp As Object
On Error GoTo ERR1
'Opens the document WHERE FORM1 IS YOUR FORM AND LIST1 IS LISTBOX
NAME
strDocName = Forms!FORM1!List1
Set objApp = CreateObject("Word.Application")
objApp.Visible = True
objApp.Documents.Open strDocName
Exit Sub
ERR1:
MsgBox "ERROR IS" + Err.Description
End Sub
as you can see the name of the list box is list1 and the name of the
form is form1
this doesn't check if the file is missing.
if you have word in your reference this should work.
Lewie
lewie wrote:
OH we will need to get rid of the other code you are not using so you
can make a new db and just put this in or if this is the only code get
rid of the rest and then go to the debug tab and press compile. We
could be getting errors from the other code.
Lewie
lewie wrote:
We haven't hooked up the button yet we will do this in steps.
do you know how to use debug menu? in code window using the
view/menu/debug selection will place the debug menu at the top. and if
you hover over the selection with the writing and the arrow it will say
"step into". when you click it it will step through the code.
so palce the cursor on the call newtest line and start stepping. When
you get to the
Documents.Open FileName:=defaultDir & "TEST.DOC"
line and click it should open the document. Ok.
Lewie
Susan H. White wrote:
Lewie, I created a second module for Public Sub newtest() as you directed.
Again triple checked. Included each line except your"OK this will open a test
document . . ." and "this will run it, etc. . . ." Created a test.doc file in
C drive and tested that by the Run process. Then I created a test.doc
pathway in my list box. Then held my breath and pushed the button and . . . .
nothing! Went back to step through the module and I get right away "Compile
Error, variable not defined." Susan

"lewie" wrote:

Public Sub newtest()


defaultDir = "C:\" 'Options.DefaultFilePath(wdDocumentsPath)
defaultDir = defaultDir '+ "Test.doc"
With Application.FileSearch
.FileName = "Test.doc"
.LookIn = defaultDir
.Execute
If .FoundFiles.Count = 1 Then
Documents.Open FileName:=defaultDir & "TEST.DOC"
Else
MsgBox "Test.doc file was not found"
End If
End With
End Sub
ok this will open a text doc named test.doc in c: drive
Public Function x()
Call newtest
End Function
this will run it
then when this is working all we have to do is assign what is in the
dropdown to these values
put this code in module and step thru it.
using the debug bar.

Lewie
Rick Brandt wrote:
"Susan H. White" wrote in message
...
In a form, I have a listbox based on a table that contains Section,
Subsection, Page and Pathway. What I want to have happen is that selecting
one of the lines in the listbox automatically activates the Pathway so that
the specified document comes up in WORD.

I'm just unable to do this, despite hours of frustration with macros,
coding, etc. Can anyone help?

What code are you using now? I would expect something like...

Application.FollowHyperLink Me.ListBoxName.Column(3)

--
Rick Brandt, Microsoft Access MVP
Email (as appropriate) to...
RBrandt at Hunter dot com







  #28  
Old January 11th, 2007, 03:58 PM posted to microsoft.public.access.tablesdbdesign
Susan H. White
external usenet poster
 
Posts: 26
Default Getting from Access to Word

My answer from this morning didn't post either! But I did get your (missing)
answer this morning. I have had g:\test.doc in the list box from the time I
created Lewie. It's one of three entries in Listbox1. If I select that record
and push the button, I get the blank WORD document. If I select it and then
step through the code, the same thing happens when I get down to
ojbApp.Documents.Open strDocName

"lewie" wrote:

My answer from yesterday didn't post hmmmm.
Ya you have to put g:\test.doc in the list box and select it.
Lewie
Susan H. White wrote:
Morning Lewie! Yes, I stepped through. Got down to ojbApp.Documents.Open
strDocName and I get a BLANK Word document, same as before - and same as what
happens now when, at the Form level, I hit the button. I know we told Access
that filepath is G:\test.doc. But do i also need to put G:\test.doc in place
of strDocName? And if so, what about all the other entries in the real Table?
Maybe we need to say that filepath is "filepath" which is the name of the
column heading in my table1??"

"lewie" wrote:

So did you step through this one. using debug.
That will give you an idea if it is working correctly. Is the listbox
named list1 and the form named form1?
objApp.Documents.Open strDocName is where the doc should open.
the command button is named cmdOpenWordDoc thus the click event is
Private Sub cmdOpenWordDoc_Click()
If you can step through it it would really help.
I am experimenting with this stuff right now too so it is a learning
experience.
That other stuff i did would work sometimes and not others. I couldn't
figure out if it was being cached or what. Anyway this works every time
for me and i am working on concatonating columns in a list box so you
could have the path in one and the file in the other. I am also messing
with the file dialog box it seems promising.
Lewie
Susan H. White wrote:
OK Lewie: I started all over. Created a new database named Lewie with one
form containing a listbox based on one table. Then added the button and put
on that code. Then created a module with that code.

Then back to the form, I pushed the button. Got a Microsoft Word header(!!!)
but the message that This File could not be found, check spelling blah,blah.

So I think we must be very close. I backed out and went the RUN route and
brought up the file without incident. Doublechecked that my table has the
correct filepath and spelling.

I changed two things. One is that I rewrote your line filepath =
"c:\test.doc" to "g:\test.doc" because that's where both Lewie and the file
are.

Another is in your code for the module, I left out your all CAPS WHERE FORM1
IS YOUR FORM AND LIST1 IS LISTBOX NAME. Assumed you were writing that to me
so the line is just 'Opens the document. Is this the problem?

"Susan H. White" wrote:

Lewie. You really are a prince. I didn't see your message until just now, and
I will try to duplicate your actions. Meanwhile, I copied and renamed my file
and then deleted the first module we wrote. Then I tried the debug process
you described on the NewTest module. Immediately got the message "Compile
error, variable not defined." The module, incidentally, says at the top
"Option Compare Database" and, next line, "option explicit." Then goes on to
Public Sub newtest(), etc.

Before you waste any more time on this, let me follow your latest idea from
top to bottom and see if I can make that work. Susan

"lewie" wrote:

I started over with a list box that contains one field c:\test.doc
when i selected it it open that doc in word.
this code goes in the click event of the button
Private Sub cmdOpenWordDoc_Click()
'Check to see that there is a document file path associated with the
record
Dim filepath As String
filepath = "c:\test.doc"
If IsNull(filepath) Or filepath = "" Then
MsgBox "Please Ensure There Is A File Path Associated For This
Document", _
vbInformation, "Action Cancelled"
Exit Sub
Else
'Check that the document specified in the file path is actually
there
If (Dir(filepath) = "") Then
MsgBox "Document Does Not Exist In The Specified Location",
_
vbExclamation, "Action Cancelled"
Exit Sub
Else
'Opens document in Word
Call OpenWordDoc(filepath)
End If
End If
End Sub
as u can see the name of the button was cmdOpenWordDoc
then in the module I placed this code:
Sub OpenWordDoc(strDocName As String)
Dim objApp As Object
On Error GoTo ERR1
'Opens the document WHERE FORM1 IS YOUR FORM AND LIST1 IS LISTBOX
NAME
strDocName = Forms!FORM1!List1
Set objApp = CreateObject("Word.Application")
objApp.Visible = True
objApp.Documents.Open strDocName
Exit Sub
ERR1:
MsgBox "ERROR IS" + Err.Description
End Sub
as you can see the name of the list box is list1 and the name of the
form is form1
this doesn't check if the file is missing.
if you have word in your reference this should work.
Lewie
lewie wrote:
OH we will need to get rid of the other code you are not using so you
can make a new db and just put this in or if this is the only code get
rid of the rest and then go to the debug tab and press compile. We
could be getting errors from the other code.
Lewie
lewie wrote:
We haven't hooked up the button yet we will do this in steps.
do you know how to use debug menu? in code window using the
view/menu/debug selection will place the debug menu at the top. and if
you hover over the selection with the writing and the arrow it will say
"step into". when you click it it will step through the code.
so palce the cursor on the call newtest line and start stepping. When
you get to the
Documents.Open FileName:=defaultDir & "TEST.DOC"
line and click it should open the document. Ok.
Lewie
Susan H. White wrote:
Lewie, I created a second module for Public Sub newtest() as you directed.
Again triple checked. Included each line except your"OK this will open a test
document . . ." and "this will run it, etc. . . ." Created a test.doc file in
C drive and tested that by the Run process. Then I created a test.doc
pathway in my list box. Then held my breath and pushed the button and . . . .
nothing! Went back to step through the module and I get right away "Compile
Error, variable not defined." Susan

"lewie" wrote:

Public Sub newtest()


defaultDir = "C:\" 'Options.DefaultFilePath(wdDocumentsPath)
defaultDir = defaultDir '+ "Test.doc"
With Application.FileSearch
.FileName = "Test.doc"
.LookIn = defaultDir
.Execute
If .FoundFiles.Count = 1 Then
Documents.Open FileName:=defaultDir & "TEST.DOC"
Else
MsgBox "Test.doc file was not found"
End If
End With
End Sub
ok this will open a text doc named test.doc in c: drive
Public Function x()
Call newtest
End Function
this will run it
then when this is working all we have to do is assign what is in the
dropdown to these values
put this code in module and step thru it.
using the debug bar.

Lewie
Rick Brandt wrote:
"Susan H. White" wrote in message
...
In a form, I have a listbox based on a table that contains Section,
Subsection, Page and Pathway. What I want to have happen is that selecting
one of the lines in the listbox automatically activates the Pathway so that
the specified document comes up in WORD.

I'm just unable to do this, despite hours of frustration with macros,
coding, etc. Can anyone help?

What code are you using now? I would expect something like...

Application.FollowHyperLink Me.ListBoxName.Column(3)

--
Rick Brandt, Microsoft Access MVP
Email (as appropriate) to...
RBrandt at Hunter dot com








  #29  
Old January 12th, 2007, 03:24 PM posted to microsoft.public.access.tablesdbdesign
lewie
external usenet poster
 
Posts: 40
Default Getting from Access to Word

Hi Susan,
you need to put g:\test.doc in the listbox and select it.
This is the third day I have sent the same message!!!!!
Lewie
Susan H. White wrote:
Morning Lewie! Yes, I stepped through. Got down to ojbApp.Documents.Open
strDocName and I get a BLANK Word document, same as before - and same as what
happens now when, at the Form level, I hit the button. I know we told Access
that filepath is G:\test.doc. But do i also need to put G:\test.doc in place
of strDocName? And if so, what about all the other entries in the real Table?
Maybe we need to say that filepath is "filepath" which is the name of the
column heading in my table1??"

"lewie" wrote:

So did you step through this one. using debug.
That will give you an idea if it is working correctly. Is the listbox
named list1 and the form named form1?
objApp.Documents.Open strDocName is where the doc should open.
the command button is named cmdOpenWordDoc thus the click event is
Private Sub cmdOpenWordDoc_Click()
If you can step through it it would really help.
I am experimenting with this stuff right now too so it is a learning
experience.
That other stuff i did would work sometimes and not others. I couldn't
figure out if it was being cached or what. Anyway this works every time
for me and i am working on concatonating columns in a list box so you
could have the path in one and the file in the other. I am also messing
with the file dialog box it seems promising.
Lewie
Susan H. White wrote:
OK Lewie: I started all over. Created a new database named Lewie with one
form containing a listbox based on one table. Then added the button and put
on that code. Then created a module with that code.

Then back to the form, I pushed the button. Got a Microsoft Word header(!!!)
but the message that This File could not be found, check spelling blah,blah.

So I think we must be very close. I backed out and went the RUN route and
brought up the file without incident. Doublechecked that my table has the
correct filepath and spelling.

I changed two things. One is that I rewrote your line filepath =
"c:\test.doc" to "g:\test.doc" because that's where both Lewie and the file
are.

Another is in your code for the module, I left out your all CAPS WHERE FORM1
IS YOUR FORM AND LIST1 IS LISTBOX NAME. Assumed you were writing that to me
so the line is just 'Opens the document. Is this the problem?

"Susan H. White" wrote:

Lewie. You really are a prince. I didn't see your message until just now, and
I will try to duplicate your actions. Meanwhile, I copied and renamed my file
and then deleted the first module we wrote. Then I tried the debug process
you described on the NewTest module. Immediately got the message "Compile
error, variable not defined." The module, incidentally, says at the top
"Option Compare Database" and, next line, "option explicit." Then goes on to
Public Sub newtest(), etc.

Before you waste any more time on this, let me follow your latest idea from
top to bottom and see if I can make that work. Susan

"lewie" wrote:

I started over with a list box that contains one field c:\test.doc
when i selected it it open that doc in word.
this code goes in the click event of the button
Private Sub cmdOpenWordDoc_Click()
'Check to see that there is a document file path associated with the
record
Dim filepath As String
filepath = "c:\test.doc"
If IsNull(filepath) Or filepath = "" Then
MsgBox "Please Ensure There Is A File Path Associated For This
Document", _
vbInformation, "Action Cancelled"
Exit Sub
Else
'Check that the document specified in the file path is actually
there
If (Dir(filepath) = "") Then
MsgBox "Document Does Not Exist In The Specified Location",
_
vbExclamation, "Action Cancelled"
Exit Sub
Else
'Opens document in Word
Call OpenWordDoc(filepath)
End If
End If
End Sub
as u can see the name of the button was cmdOpenWordDoc
then in the module I placed this code:
Sub OpenWordDoc(strDocName As String)
Dim objApp As Object
On Error GoTo ERR1
'Opens the document WHERE FORM1 IS YOUR FORM AND LIST1 IS LISTBOX
NAME
strDocName = Forms!FORM1!List1
Set objApp = CreateObject("Word.Application")
objApp.Visible = True
objApp.Documents.Open strDocName
Exit Sub
ERR1:
MsgBox "ERROR IS" + Err.Description
End Sub
as you can see the name of the list box is list1 and the name of the
form is form1
this doesn't check if the file is missing.
if you have word in your reference this should work.
Lewie
lewie wrote:
OH we will need to get rid of the other code you are not using so you
can make a new db and just put this in or if this is the only code get
rid of the rest and then go to the debug tab and press compile. We
could be getting errors from the other code.
Lewie
lewie wrote:
We haven't hooked up the button yet we will do this in steps.
do you know how to use debug menu? in code window using the
view/menu/debug selection will place the debug menu at the top. and if
you hover over the selection with the writing and the arrow it will say
"step into". when you click it it will step through the code.
so palce the cursor on the call newtest line and start stepping. When
you get to the
Documents.Open FileName:=defaultDir & "TEST.DOC"
line and click it should open the document. Ok.
Lewie
Susan H. White wrote:
Lewie, I created a second module for Public Sub newtest() as you directed.
Again triple checked. Included each line except your"OK this will open a test
document . . ." and "this will run it, etc. . . ." Created a test.doc file in
C drive and tested that by the Run process. Then I created a test.doc
pathway in my list box. Then held my breath and pushed the button and . . . .
nothing! Went back to step through the module and I get right away "Compile
Error, variable not defined." Susan

"lewie" wrote:

Public Sub newtest()


defaultDir = "C:\" 'Options.DefaultFilePath(wdDocumentsPath)
defaultDir = defaultDir '+ "Test.doc"
With Application.FileSearch
.FileName = "Test.doc"
.LookIn = defaultDir
.Execute
If .FoundFiles.Count = 1 Then
Documents.Open FileName:=defaultDir & "TEST.DOC"
Else
MsgBox "Test.doc file was not found"
End If
End With
End Sub
ok this will open a text doc named test.doc in c: drive
Public Function x()
Call newtest
End Function
this will run it
then when this is working all we have to do is assign what is in the
dropdown to these values
put this code in module and step thru it.
using the debug bar.

Lewie
Rick Brandt wrote:
"Susan H. White" wrote in message
...
In a form, I have a listbox based on a table that contains Section,
Subsection, Page and Pathway. What I want to have happen is that selecting
one of the lines in the listbox automatically activates the Pathway so that
the specified document comes up in WORD.

I'm just unable to do this, despite hours of frustration with macros,
coding, etc. Can anyone help?

What code are you using now? I would expect something like...

Application.FollowHyperLink Me.ListBoxName.Column(3)

--
Rick Brandt, Microsoft Access MVP
Email (as appropriate) to...
RBrandt at Hunter dot com







 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 02:56 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.