Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Opening word docs from access

Status
Not open for further replies.

domino3

MIS
May 20, 2003
307
GB
I have already put this in a different forum, but I think that I should have put it in this one instead.

I have word document called mailmerge.doc which I would like to be able to open and run by clicking a command button on a form in access, after selecting query criteria from a combo box called combo_groups on the same form. I've tried reading the earlier threads but have got totally confused. Any help would be gratefully received. Thank you.
 
The forms forum is a suitable forum. I do not think you have provided sufficient information to receive an answer. For example, what do you expect to happen to the selected query criteria?

Mailmerging is a very common thing with Access, have you looked at the FAQs?



This post also occurs at:
Running a word doc from a command button in Access
thread702-1220030
 
Sorry about the two posts. I originally posted into this forum, then thought I should have used the other one instead. What I currently have is a mailmerge in word which the users in my office open manually then type in the criteria they need. They would like to be able to have a drop down list to choose from, to avoid typos. I thought the way round it would be to select an option from a combo box in a form in access, then click a command button which opens a mailmerge word document and inserts the option from the combo box as the criteria for the query that runs the mailmerge. I have looked at the faqs, but I have got very confused, so any help would be appreciated.
 
No problem. If your mailmerge document is based on a linked query, you may be able to do something like this:
Code:
Private Sub cmdWord_Click()
Dim qdf As QueryDef
Dim PathAndWord, PathAndDoc
    
    'Modify the query according to the criteria chosen 
    'from cboWhere 
    Set qdf = CurrentDb.QueryDefs("qryMailMerge")
    qdf.SQL = "SELECT Title, Forename, Surname, Address FROM tblPersons " _
            & "WHERE " & Me.cboWhere
    Set qdf = Nothing
    
    'Details of Word and Mailmerge.doc
    PathAndWord = "C:\Program Files\Microsoft Office\Office\WinWord.Exe"
    PathAndDoc = "C:\Docs\Mailmerge.doc"
    
    'Shell Word
    RetVal = Shell("""" & PathAndWord & """" & " " & """" & PathAndDoc & """", vbNormalFocus)
End Sub
The general idea is that the mailmerge document is already built using qryMailMerge as the data source. Users then select a set of criteria from cboWhere, the SQL for the query is changed to include the criteria (Where) and the previously built Word document is opened. This is not a particularly secure way of going about things as users are interacting with the master document, but it may suit. You will need to add error coding to check everything. For example, this code will fall over if cboWhere is Null. You can either change the coding, or ensure that cboWhere is completed. Please make sure that the same fields are built into the query each time.
 
I've had to rethink my last request for help, as we have so many mailmerges that I don't think it will be practical to have command buttons for each mailmerge request.

Instead, is it possible to enter the options directly into word mailmerge filter , and then have that drop down list appear to act as a filter in the mailmerge itself?

 
Hi!

I think you will run into a problem with this. Word will open the data source and, if the data source is already open, Word will open a separate copy of the source. Therefore the data in the combo box will not be available to Word when the mailmerge runs.

One way around this is to change your query to a Create Table query and then, when the button is clicked, delete the mailmerge table and run the query to recreate the table using the data from the combobox. Then open the Word document and run the mailmerge.

One more thought. You can set up a macro in the Word document to run the mailmerge. If you then call the macro autoexec, the macro will run automatically when the Word document is opened. Then you can use two buttons, one to create the data source and one to open the document. For the button to open the Word document all you need to do is set the hyperlink property of the button to the path of the document and it will open.

hth


Jeff Bridgham
Purdue University
Graduate School
Data Analyst
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top