?
Solved

Access query to open another application (SQL CODE)

Posted on 2008-06-26
5
Medium Priority
?
269 Views
Last Modified: 2012-05-05
I have a query that pulls data for employees that are 65 and older, within that query there is a make table command to populate the table every time I run the query. I have created a mail merge document in MS Word 2003 to source the data from the table the query populates. All I want to do is make the original query button to open up the word mail merge documents I created. Because the mail merge doc automatically updates the source files when you open the doc the data should always be valid.
The MS Word doc name is: Mail Merge Design.doc
The Query Name is: qry_AddressLabels
The Table Name is:Address Labels for 65+

Thank you!
0
Comment
Question by:jaugermeister
  • 3
  • 2
5 Comments
 

Author Comment

by:jaugermeister
ID: 21882448
Okay it appears I'm on my own for now...
This is what I gathered so far from searching, but it still does not work in the VB editor lines of code.

  Dim LWordDoc As String
    Dim oApp As Object

    'Path to the word document
    LWordDoc = "S:\Consult Referral Tracking - RM\Mail Merge Design.doc"
    oApp.Documents.Open filename:=LWordDoc


How can I make this work? what am I missing here, Access doesn't have an issue with the syntax it debugs just fine but does nothing when I run the query.
0
 
LVL 14

Expert Comment

by:JohnK813
ID: 21883908
My first suggestion is to add the double quote character (") to each side of your string.  The double quote is represented by ASCII character 34.

'Path to the word document
    LWordDoc = chr(34) & "S:\Consult Referral Tracking - RM\Mail Merge Design.doc" & chr(34)
    oApp.Documents.Open filename:=LWordDoc

If that doesn't work, I have an Access 2002 DB that opens Word using the Shell() command.  Here's an example:

  shellpath = Chr(34) & "c:\program files\microsoft office\office" & _
    CInt(Application.Version) & "\winword.exe" & Chr(34) & " " & _
    Chr(34) & "S:\Consult Referral Tracking - RM\Mail Merge Design.doc" & Chr(34)
  Shell (shellpath)
0
 

Author Comment

by:jaugermeister
ID: 21885076
don't know what I'm doing wrong here, that doesn't work. the example above debugs just fine like my other string but when I run the query everything works except the word doc doesn't open up...

this is where I'm placing the line of code.

Private Sub cmdAddressLabels_Click()
On Error GoTo Err_cmdAddressLabels_Click

    Dim stDocName As String

    stDocName = "qry_AddressLabels"
    DoCmd.OpenQuery stDocName, acNormal, acEdit
   
Exit_cmdAddressLabels_Click:
    Exit Sub

Err_cmdAddressLabels_Click:
    MsgBox Err.Description
    Resume Exit_cmdAddressLabels_Click
    Exit Sub
   
   
   shellpath = Chr(34) & "c:\program files\microsoft office\office" & _
    CInt(Application.Version) & "\winword.exe" & Chr(34) & " " & _
    Chr(34) & "S:\Consult Referral Tracking - RM\Mail Merge Design.doc" & Chr(34)
  Shell (shellpath)
   
End Sub
0
 

Accepted Solution

by:
jaugermeister earned 0 total points
ID: 21885142
Adding a screen shot so you can see where I'm placing the text...
I get this dialoge box via opening the properties of the button and clicking the (...) to the right of the click action.


Open-Word.bmp
0
 
LVL 14

Assisted Solution

by:JohnK813
JohnK813 earned 2000 total points
ID: 21886142
Where you have the shellpath and Shell() lines now, Access thinks they're part of Err_cmdAddressLabels_Click.  So technically they'd only be run if you get an error.  But you also have the Resume and Exit Sub before that, meaning they never get run.

Try moving the shellpath and Shell() lines before the Exit_cmdAddressLabels_Click line.
0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have had my own IT business for a very long time. I started mostly with hardware and after about a year started to notice a common theme. I had shelves with software boxes -- Peachtree, Quicken, Sage, Ouickbooks -- and yet most of my clients were…
Windows Explorer let you handle zip folders nearly as any other folder: Copy, move, change, and delete, etc. In VBA you can also handle normal files and folders, but zip folders takes a little more - and that you'll find here.
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

589 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question