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. |
|
|
Thread Tools | Display Modes |
#11
|
|||
|
|||
Getting from Access to Word
Thanks Lewie! I fear Rick has pulled out all his hair trying to deal with me!
Please read my response to him about the error message I get having installed the code as he suggested. I'll wait till later in the day and then try your solution. But If the new error message 432 is the clue we've been waiting for, let me know before I mess it all up again. Susan "lewie" wrote: found this: Question From my Microsoft Access form I would like to hyperlink to a Microsoft Word document. At present each record contains a document name and a full file path to where the document is stored. I would like to open Word and view the specified document. Answer The details below show how to Open the Microsoft Word application and view the document specified in the associated record on the form. Paste the following code into a module: '------------------Code Start----------------------- Sub OpenWordDoc(strDocName As String) Dim objApp As Object 'Opens the document Set objApp = CreateObject("Word.Application") objApp.Visible = True objApp.Documents.Open strDocName End Sub '------------------Code End------------------------- Then from the On Click event of the command button on the form (named cmdOpenWordDoc in this example) paste the following (where Me.FilePath is the name of the control on the form storing the path to the associated file): '------------------Code Start----------------------- Private Sub cmdOpenWordDoc_Click() 'Check to see that there is a document file path associated with the record If IsNull(Me.FilePath) Or Me.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(Me.FilePath) = "") Then MsgBox "Document Does Not Exist In The Specified Location", _ vbExclamation, "Action Cancelled" Exit Sub Else 'Opens document in Word Call OpenWordDoc(Me.FilePath) End If End If End Sub '------------------Code End----------------------- This will initially check to see that the Microsoft Access record contains a File Path in the control labelled FilePath. If there is no entry in this field a message box is displayed to inform the user and the action is cancelled. Error when there is no file path associated with the record If there is a file path entered, the next section If (Dir(Me.FilePath) = "") checks to see that the document is present in the specified location. If there is no document present the action is again cancelled and a message box informs the user. Error when the document does not exist in the specifed location You can now open up Microsoft Word documents stored in any location as long as you specify the full path to the file. My guess would be you don't have the reference set. Lewie Rick Brandt wrote: "Susan H. White" wrote in message ... OK I'll try that Rick. But before I go off on another trip to frustration, can you tell me what "Chr(34)" is? We've not talked about that one before and I don't want to complicate the situation unless you say I need to. Thanks again, Susan Chr(34) is the double-quote character. Using the Chr() function eliminates the need to put double-quotes around your double-quotes (which can get confusing). Do you have at least one path that contains no spaces that you can test with, even if that means creating a temporary one? That should tell you if that is the problem with what you have now. -- Rick Brandt, Microsoft Access MVP Email (as appropriate) to... RBrandt at Hunter dot com |
#12
|
|||
|
|||
Getting from Access to Word
Lewie: Could the problem be the basic structure? I have a form (actually 14
different forms) each with a list box built from the appropriate table which is actually a Table of Contents with columns for auto#, Section, Detail, Page, and Pathway. Is the problem that Access can't tell which document I want even though I double click the specific record in the list box? Thanks, Susan "lewie" wrote: found this: Question From my Microsoft Access form I would like to hyperlink to a Microsoft Word document. At present each record contains a document name and a full file path to where the document is stored. I would like to open Word and view the specified document. Answer The details below show how to Open the Microsoft Word application and view the document specified in the associated record on the form. Paste the following code into a module: '------------------Code Start----------------------- Sub OpenWordDoc(strDocName As String) Dim objApp As Object 'Opens the document Set objApp = CreateObject("Word.Application") objApp.Visible = True objApp.Documents.Open strDocName End Sub '------------------Code End------------------------- Then from the On Click event of the command button on the form (named cmdOpenWordDoc in this example) paste the following (where Me.FilePath is the name of the control on the form storing the path to the associated file): '------------------Code Start----------------------- Private Sub cmdOpenWordDoc_Click() 'Check to see that there is a document file path associated with the record If IsNull(Me.FilePath) Or Me.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(Me.FilePath) = "") Then MsgBox "Document Does Not Exist In The Specified Location", _ vbExclamation, "Action Cancelled" Exit Sub Else 'Opens document in Word Call OpenWordDoc(Me.FilePath) End If End If End Sub '------------------Code End----------------------- This will initially check to see that the Microsoft Access record contains a File Path in the control labelled FilePath. If there is no entry in this field a message box is displayed to inform the user and the action is cancelled. Error when there is no file path associated with the record If there is a file path entered, the next section If (Dir(Me.FilePath) = "") checks to see that the document is present in the specified location. If there is no document present the action is again cancelled and a message box informs the user. Error when the document does not exist in the specifed location You can now open up Microsoft Word documents stored in any location as long as you specify the full path to the file. My guess would be you don't have the reference set. Lewie Rick Brandt wrote: "Susan H. White" wrote in message ... OK I'll try that Rick. But before I go off on another trip to frustration, can you tell me what "Chr(34)" is? We've not talked about that one before and I don't want to complicate the situation unless you say I need to. Thanks again, Susan Chr(34) is the double-quote character. Using the Chr() function eliminates the need to put double-quotes around your double-quotes (which can get confusing). Do you have at least one path that contains no spaces that you can test with, even if that means creating a temporary one? That should tell you if that is the problem with what you have now. -- Rick Brandt, Microsoft Access MVP Email (as appropriate) to... RBrandt at Hunter dot com |
#13
|
|||
|
|||
Getting from Access to Word
Lewie, I followed your instructions and triple checked. Put on a new control
button named CmdOpenWordDoc, placed the second batch of code in its "On Click event". The first batch of code is now in a module, as directed. Saved everything and renamed the listbox Me.FilePath - the control on the form storing the path to the associated file, as you said. Now I get no reaction at all when I push the control button. I'm wondering if we failed to activate the module? Susan "lewie" wrote: found this: Question From my Microsoft Access form I would like to hyperlink to a Microsoft Word document. At present each record contains a document name and a full file path to where the document is stored. I would like to open Word and view the specified document. Answer The details below show how to Open the Microsoft Word application and view the document specified in the associated record on the form. Paste the following code into a module: '------------------Code Start----------------------- Sub OpenWordDoc(strDocName As String) Dim objApp As Object 'Opens the document Set objApp = CreateObject("Word.Application") objApp.Visible = True objApp.Documents.Open strDocName End Sub '------------------Code End------------------------- Then from the On Click event of the command button on the form (named cmdOpenWordDoc in this example) paste the following (where Me.FilePath is the name of the control on the form storing the path to the associated file): '------------------Code Start----------------------- Private Sub cmdOpenWordDoc_Click() 'Check to see that there is a document file path associated with the record If IsNull(Me.FilePath) Or Me.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(Me.FilePath) = "") Then MsgBox "Document Does Not Exist In The Specified Location", _ vbExclamation, "Action Cancelled" Exit Sub Else 'Opens document in Word Call OpenWordDoc(Me.FilePath) End If End If End Sub '------------------Code End----------------------- This will initially check to see that the Microsoft Access record contains a File Path in the control labelled FilePath. If there is no entry in this field a message box is displayed to inform the user and the action is cancelled. Error when there is no file path associated with the record If there is a file path entered, the next section If (Dir(Me.FilePath) = "") checks to see that the document is present in the specified location. If there is no document present the action is again cancelled and a message box informs the user. Error when the document does not exist in the specifed location You can now open up Microsoft Word documents stored in any location as long as you specify the full path to the file. My guess would be you don't have the reference set. Lewie Rick Brandt wrote: "Susan H. White" wrote in message ... OK I'll try that Rick. But before I go off on another trip to frustration, can you tell me what "Chr(34)" is? We've not talked about that one before and I don't want to complicate the situation unless you say I need to. Thanks again, Susan Chr(34) is the double-quote character. Using the Chr() function eliminates the need to put double-quotes around your double-quotes (which can get confusing). Do you have at least one path that contains no spaces that you can test with, even if that means creating a temporary one? That should tell you if that is the problem with what you have now. -- Rick Brandt, Microsoft Access MVP Email (as appropriate) to... RBrandt at Hunter dot com |
#14
|
|||
|
|||
Getting from Access to Word
Susan H. White wrote: Lewie, I followed your instructions and triple checked. Put on a new control button named CmdOpenWordDoc, placed the second batch of code in its "On Click event". The first batch of code is now in a module, as directed. Saved everything and renamed the listbox Me.FilePath - the control on the form storing the path to the associated file, as you said. Now I get no reaction at all when I push the control button. I'm wondering if we failed to activate the module? Susan "lewie" wrote: found this: Question From my Microsoft Access form I would like to hyperlink to a Microsoft Word document. At present each record contains a document name and a full file path to where the document is stored. I would like to open Word and view the specified document. Answer The details below show how to Open the Microsoft Word application and view the document specified in the associated record on the form. Paste the following code into a module: '------------------Code Start----------------------- Sub OpenWordDoc(strDocName As String) Dim objApp As Object 'Opens the document Set objApp = CreateObject("Word.Application") objApp.Visible = True objApp.Documents.Open strDocName End Sub '------------------Code End------------------------- Then from the On Click event of the command button on the form (named cmdOpenWordDoc in this example) paste the following (where Me.FilePath is the name of the control on the form storing the path to the associated file): '------------------Code Start----------------------- Private Sub cmdOpenWordDoc_Click() 'Check to see that there is a document file path associated with the record If IsNull(Me.FilePath) Or Me.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(Me.FilePath) = "") Then MsgBox "Document Does Not Exist In The Specified Location", _ vbExclamation, "Action Cancelled" Exit Sub Else 'Opens document in Word Call OpenWordDoc(Me.FilePath) End If End If End Sub '------------------Code End----------------------- This will initially check to see that the Microsoft Access record contains a File Path in the control labelled FilePath. If there is no entry in this field a message box is displayed to inform the user and the action is cancelled. Error when there is no file path associated with the record If there is a file path entered, the next section If (Dir(Me.FilePath) = "") checks to see that the document is present in the specified location. If there is no document present the action is again cancelled and a message box informs the user. Error when the document does not exist in the specifed location You can now open up Microsoft Word documents stored in any location as long as you specify the full path to the file. My guess would be you don't have the reference set. Lewie Rick Brandt wrote: "Susan H. White" wrote in message ... OK I'll try that Rick. But before I go off on another trip to frustration, can you tell me what "Chr(34)" is? We've not talked about that one before and I don't want to complicate the situation unless you say I need to. Thanks again, Susan Chr(34) is the double-quote character. Using the Chr() function eliminates the need to put double-quotes around your double-quotes (which can get confusing). Do you have at least one path that contains no spaces that you can test with, even if that means creating a temporary one? That should tell you if that is the problem with what you have now. -- Rick Brandt, Microsoft Access MVP Email (as appropriate) to... RBrandt at Hunter dot com |
#15
|
|||
|
|||
Getting from Access to Word
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 |
#16
|
|||
|
|||
Getting from Access to Word
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 |
#17
|
|||
|
|||
Getting from Access to Word
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 |
#18
|
|||
|
|||
Getting from Access to Word
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 |
#19
|
|||
|
|||
Getting from Access to Word
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 |
#20
|
|||
|
|||
Getting from Access to Word
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 | |
|
|