473,385 Members | 1,769 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Open a Word Doc from Access

How do i or can I open a word document directly from Access? I would like to
be able for the user to click a button on my form to open a word document
and then also run a macro in Word.

Thanks in advance
Nov 13 '05 #1
3 5793
Hi
If you are using MS Access 2003,
If you drag a button on to the form, a whizard pops up automatically,
select Applications > MS Word
best Regards,
Chandra
http://groups.msn.com/SQLResource/
http://chanduas.blogspot.com/
---------------------------------------

*** Sent via Developersdex http://www.developersdex.com ***
Nov 13 '05 #2
Per Andy Davis:
How do i or can I open a word document directly from Access? I would like to
be able for the user to click a button on my form to open a word document
and then also run a macro in Word.


It will involve writing some VBA code.

This isn't exactly what you're describing, but it's probably close enough to the
the idea:
================================================== ==========================
Private Function wordBegin(theModelName) As String
3000 debugStackPush mModuleName & ": wordBegin: "
3001 On Error GoTo wordBegin_err

' PURPOSE: - Start an instance of MS WORD or use an existing instance
' - Open up a model document and saves it under a unique DOS 8.3
name
' - Leave a global object "gWord" pointing to the Word Basic engine
' behind the newly-opened document so the calling procedure can
OLE to it
' ACCEPTS: DOS 8.3 name of model document to be used for letter
' RETURNS: DOS 8.0 name of the newly-opend letter if successful, zero-length
string if failed
'
' NOTES: 1) We do not want to keep opening up new instances of Word every
time this routine
' is called, so we do the "= Nothing" check to see if gWord has
already been set.
' OTHO the user may have closed that instance of Word, leaving
gWord pointing to
' Neverneverland. Experimentation shows that an error 2753 is
generated in this case.
' Hence the error trap and the "userClosedWord" switch.
' 2) In the FileSaveAs, it is important to force the document type
to Word. Otherwise, if
' the models are Word 7 and the user is in Word 8, the document
will default to .RTF
' and paragraph marks will not work (.RTF needs CRLF wheras Word
used just CR)

Dim modelPath As String
Dim LetterPath As String
Dim dosName As String
Dim problemPath As String
Dim userClosedWord As Integer

Const oleError = 2753

3009 modelPath = pathDatDbGet("tblPerson") & "\Models"
3010 LetterPath = pathDatDbGet("tblPerson") & "\Letters"

On Error Resume Next
MkDir LetterPath
On Error GoTo wordBegin_err

3020 dosName = Format$(recordNumberNextGet("LetterNumber"), "00000000") & ".DOC"

wordBegin_loop:
3390 If (gWord Is Nothing) Or (userClosedWord = 1) Then
3391 Set gWord = CreateObject("Word.Application.8")
3392 End If

3395 problemPath = modelPath & "\" & theModelName
3400 gWord.ChangeFileOpenDirectory (modelPath) 'DMN
3401 gWord.Documents.Open (theModelName)

3405 problemPath = LetterPath & "\" & theModelName
3410 gWord.ChangeFileOpenDirectory (LetterPath) 'DMN
3411 gWord.ActiveDocument.SaveAs (dosName) 'DMN

3999 wordBegin = dosName

wordBegin_xit:
debugStackPop
On Error Resume Next
Exit Function

wordBegin_err:
Select Case Err
Case 2763
MsgBox "Microsoft Word is unable to find " & problemPath & ". Please
notify your administrator", 16, "Cannot Print Form Letter"
Resume wordBegin_xit
Case 2772
MsgBox "Unable to locate Microsoft Word program. Please notify your
administrator", 16, "Cannot Print Form Letter"
Resume wordBegin_xit
Case oleError, mRpcServerUnavailable
If userClosedWord = 0 Then
userClosedWord = userClosedWord + 1
Resume wordBegin_loop
Else
bugAlert "Unable to open MS Word. Suspect user may have closed
existing instance."
Resume wordBegin_xit
End If
Case Else
bugAlert ""
Resume wordBegin_xit
End Select
Resume wordBegin_xit 'Shouldn't be needed, but just in case.....
End Function
================================================== ==========================
--
PeteCresswell
Nov 13 '05 #3
Chandra

Thanks for the advice. I've tried this bit it only opens the Word
application. (Unless I've missed a specific step?). My users want the
document opening in addition to launching Word as well as they don't want to
be searching around for the file!

Might have to give Pete's code a stab if no simpler solution is available.

Many thanks again.

Dawn
"Chandra" <ch*****@discussions.hotmail.com> wrote in message
news:xG***************@news.uswest.net...
Hi
If you are using MS Access 2003,
If you drag a button on to the form, a whizard pops up automatically,
select Applications > MS Word
best Regards,
Chandra
http://groups.msn.com/SQLResource/
http://chanduas.blogspot.com/
---------------------------------------

*** Sent via Developersdex http://www.developersdex.com ***

Nov 13 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: DaveS | last post by:
Hi! I need help opening a Word document from within an Access 2000/XP mdb. I'm using Shell to open the document, but the Access code continues to run past the Shell statement. What I need is...
3
by: Bill Agee | last post by:
I need to open Word from my Access application. I would like to do without minizing Access to open word from the desktop if possible.
5
by: John Warner | last post by:
I have a wierd problem that I can't find any reference to in the knowledge base. I develop simple databases at the company where I work, and many of them are used by hundreds of employees. We all...
0
by: Niyazi | last post by:
Hi, I created application that store the data in SQL SERVER that reside on network. The client also use this application to access the resources provided with application. But is the client want...
4
by: Peppie | last post by:
Hi all, I created a button in an Access form that opens MS Word. Now I want this button also to open a specific file. How do I code this? Would it also be possible to let the user select the...
1
by: Queenslander | last post by:
Hello, I have a form (Access 2003) which brings up a clients details on screen (name, phone number, etc etc), so that an end-user can modify any of these clients details, and save the updates....
6
by: Bob Alston | last post by:
Looking for someone with experience building apps with multiple instances of forms open. I am building an app for a nonprofit organizations case workers. They provide services to the elderly. ...
1
by: dougmeece | last post by:
Good Morning Experts, I was trying to find a way to automatically open a report in MS Word when I click on a command button. I was not able to find a way to do that. I was able to open the...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.