Word and access 2013

chestera
chestera used Ask the Experts™
on
Hi EE

Still having trouble opening word in access 2013. I have the following

Dim db As DAO.Database, rs As DAO.Recordset
    Dim search
    Set db = CurrentDb
    search = "SELECT * FROM tblConfig WHERE [ConfigID] = " & 1
    Set rs = db.OpenRecordset(search)
    DocLocation = rs.Fields("DocumentLocation")
    OrgID = Me!txtOrgID
    Organisation = Me!txtOrgname
    DocFileName = "HO" & OrgID & Organisation & ".docx"
    If Right(DocLocation, 1) = "\" Then
        path = DocLocation & DocFileName
    Else
        path = DocLocation & "\" & DocFileName
    End If

   Dim wrdApp As Word.Application
   Dim wrdDoc As Word.Document
   
    If Dir(path) <> "" Then
           Set wrdApp = CreateObject("Word.Application")
           wrdApp.Visible = True
           wrdApp.Activate
           Set wrdDoc = wrdApp.Documents.Open(path)
           wrdDoc.Application.WindowState = wdWindowStateMaximize
           wrdDoc.Activate
    Else
            MsgBox ("There is no Document for this project"), vbOKOnly, "Message"
   
    End If

At the moment wdWindowsState is maximised, I have tried Normal When I run word opens in the background (Underneath the opening form)
Before I introduced the line wdWindowsState word would open minimised. I just want word to allways open over the access form. I have made form Popup and model = no. If I transfer the code and run access 2003 there is no problems. Any help appreciated

chestera
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Software Team Lead
Commented:
>>I just want word to allways open over the access form.
Not too sure and this is just a quick guess... what if you try use ShellExecute API to launch the word document? like:

Add this at the top of your module:
Public Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long

Public Function StartDoc(ByVal FileName As String, Optional CommandLine As String = "") As Long
    StartDoc = ShellExecute(0&, "Open", FileName, CommandLine, vbNullString, 1)
End Function

Open in new window

and then call it like:

 If Dir(path) <> "" Then
          StartDoc path
    Else
            MsgBox ("There is no Document for this project"), vbOKOnly, "Message"    
    End If

See if this works for you?

Author

Commented:
Ryan Chong

Thank you Ryan I will give it a try and get back to you. I will be away from PC for a while

Alan

Author

Commented:
Ryan Chong

Sorry for the delay I have been away. Tried your Shell routine this morning and it worked. Many thanks.
I hope you don't mind before I close off I have a minor problem unrelated to word. I have asked the question before some months ago and couldn't get an answer.

I work from home and I have Office 2013 installed on one of my PC''s. The office uses Microsoft 365 (office2013). Problem if I generate an accde from home and run on the office PC I get the message this program was developed in a later version of Access. I then have to recompile (accde) on a PC in the office to get it to run, It's no big deal but I would like to know why. Have you any ideas, My office is the professional version. I would have assumed Microsoft 365 would be more current than my copy is a couple of years old

Alan
Ryan ChongSoftware Team Lead

Commented:
@Alan,

Glad that it solves your problem cheers!

for your another question... actually I'm not using Microsoft 365 as well as accde file before, so I may not in a good position to answer you this. However... perhaps you can run the following script to test what's the "version" returned from both your home and office's machines, see if the home one is actually higher than the your office one.
debug.print application.Version & " " & application.Build & " " & application.ProductCode

Open in new window

Hope this gives you some clues that you want.

Author

Commented:
Ryan Chong

Thank you Ryan for all your help and that script

Alan

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial