Full Version: viewing, editing and saving Word documents from an Access Form
UtterAccess Forums > Microsoft® Access > Access Forms
AvidLearner
As a relative newcomer to database design and vba programming, I wonder if anyone could give me advice on the following.
I am designing a form in Access XP where, as well as clicking through client details (name, address, start date etc), I would like to show within the access form the 3 different word documents for each client, (about 450 clients), which document their progress through towards getting a particular care package.
deally staff could view, edit and save any update any of these documents withinin the access form, to save time opening and glancing through the each of the clients 3 documents etc.
I have linked an OLE field in a table to a bound object frame in the form and can see the document to which it's linked, but trying to edit it by double clicking, just brings up a view which does not have scroll bars. so I can only change the document within the form's bound object frame view - not further down the page outside the frame's view. Also, this does not update the original Word document either, even though I set the OLE Type Allowed property to Linked, and the Update Options property to Automatic.
Can I set up - programmatically or otherwise the form to view, edit and save these documents simply, and is this type of situation commonly used, or would it be less demanding on the database and server memory to have command buttons with hyperlinks to these documents instead? (they reside on the same server as the database file)
I have not set up any object references in VBA, and I am not sure if i am using the correct control (bound object frame) to accomplish this task. Maybe there is another control with which I am unfamiliar which would do the trick better.
Any advice would be really appreciated.
Rory
strive4peace
Instead of using an OLE object, store the path and filename.
Here is a link to code that you can modify that has a Browse button on a form to collect a file. It is looks for *.xls, but you can change it to look for .doc. Obviously, you will not want the combobox that shows sheetnames and the sheetname code behind the form as well as the code to import.
All you need to do is copy the
textbox for the filename
the Browse button and modified code
to a form you are designing.
There is general module code you will need as well.
Database to collect XLS filename and import
THere is code you can also modify -- this opens a Word document. You will have to pass the name of the file to open. Put this in a general module.
CODE
Sub OpenWordDocument(pFilename as String)
   'set up error handler
   On Error GoTo OpenWordDocument_error
  
   'if nothing sent
   if trim(nz(pFilename,"")) = 0 then exit sub
  
   Dim oApp As Object
  
   'if Word is already running, use that instance
   'temporarily turn off error handler -- skip line if there is an error
   'there will be an error using GetObject if Word is not already open
  
   On Error Resume Next
   Set oApp= GetObject(, "Word.Application")
  
   'turn on error handler again
   On Error GoTo OpenWordDocument_error
  
   'If Word was not already open, create a new instance of it
   If TypeName(oApp) = "Nothing" Then
   Set oApp = CreateObject("Word.Application")
   End If
  
   oApp.Visible = True
   oApp.Documents.Open pFilename
   'word should be open in another window
  
   'exit sub before it gets to the error handler
   Exit Sub
  
OpenWordDocument_error:
   Msgbox err.description,,"ERROR " & err.number & " OpenWordDocument"
   'press F8 to step through code -- comment (or remove) these lines after debugged
   stop
   resume next
End sub
TimK
Or use 'Web Browser' activex in a form. Then you can view or edit Word documents right in the form.
Search this forum for 'Web Browser' for more details.
frown.gif
AvidLearner
many thanks
Could this control - 'web browser' activeX - be bound to each record ...more specifically, to a client's word document? Anotherwords be bound to a clients record. How would this be done? Through a hyperlink for each client?
appreciate if you have any thoughts on that.
TimK
When you use the Web Browser activex, you just store the document names and path in a normal Text field, not OLE or Hyperlink field type. Then just feed the document name to the activex when you want to view/edit the file.
frown.gif
AvidLearner
I see. thank you.
How would you feed the path and document names to the web browser activeX control? would this be programmatically, or by using a property such as control source to bind a text field in a table containing the document names and paths?
would be grateful if you could give me some guidance
TimK
You can add a command button, cmdEdit, next to each document file name/path. Put this code on OnClick event of the button.
Private Sub cmdEdit_Click()
Me.WebBrowserActiveX.Navigate Me.DocFile
End
Change WebBrowserActiveX to your activex control name and Me.DocFile to the text box storing the document file and path.
frown.gif
AvidLearner
you have been a great help. many thanks once again. I do however have one last supplementary question regarding the activeX webBrowser. I am working with office xp professional, and i was wondering how i implement this onto my form. I have looked in the toolbox in form design - Add/Remove Buttons|Customise....categories - ActiveX controls and then down the list of commands - the only similar one I can see is AxBrowse.AxBrowser - Is this the same thing? or are you referring to a control that might be in the office xp developer version of office?

if that's the case, do you know if WebBrowserActiveX is available as a download anywhere?
TimK
Look for 'Microsoft Web Browser'. Working with Web Browser is tricky, check this Post out.
frown.gif
AvidLearner
Found it. Once again, thank you. Will try it out and let you know how it went. Cheers!
AvidLearner
have set up microsoft web browser in a form, and it loads the relevent document from the text box, which I have used to store paths to files.
One problem is that when I click on the command button to load the word document into the web browser, it throws up a dialog box warning about opening files and has four choices Open, Save, Cancel and More Information - which for a frequent user clicking to open many different word documents on a private network (where the files are safe) is going to get pretty tedious. Do you know how I could programmatically stop this diag box from occuring (there is a box to check to stop it appearing, but this does not work).
Also would you know how to save and cancel edits to the documents from the browser once the user has finnished looking at it.
I have looked around for this information, but I have had great difficulty finding it.
any help would be most appreciated.
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.