Need some help - trying to be nice to my users!

  • Thread starter Thread starter Douglas J. Steele
  • Start date Start date
D

Douglas J. Steele

Not sure about this, but try creating your own form and opening it as modal
(Windowmode:=acDialog), rather than using the message box.
 
Hi

I am using the following code to launch Word from Within Access and load a
specific letter for the user to print. However we have a number of printers
( each with multiple drawers) and the letters require paper from different
soyrces, also some letters are Double sided and others not.

Once the Word document was loaded I wanjted to display the text contained
with MsgBox PMessage so that the user would get a prompt.

However, the box is appearing behding the Word Window. Is there anyway to
make it appear at the front?

Than ks

Alex

clsPBar.ShowProgress
clsPBar.TextMsg = "Launching Microsoft Word...please wait..."


On Error GoTo CreateWordApp
Set WordApp = GetObject(, "Word.Application")
On Error GoTo 0

Set WordDoc = WordApp.Documents.Open(strWordDoc)
WordApp.Visible = True

MsgBox PMessage, , "The Modbury Group"


AppActivate "Microsoft Word"
WordApp.WindowState = 0 'wdWindowStateRestore

clsPBar.HideProgress

Exit Function

CreateWordApp:

Set WordApp = CreateObject("Word.Application")
Resume Next
 
Hi Douglas - thanks v much for your input.

Tried what you suggested, but the form still opens behind the Word
application.

Alex
 
Alex, these kinds of inter-application interaction can be the devil to get
working properly.

AFAIK there is no way to get the Access form displayed on top of the Word
document, using normal VBA. (But I'm happy to be corrected on that!)

Perhaps there is a win32 API to move it to the front of the desktop window
order. But personally, I haven't managed to find one that is supported (&
works properly) across all win32 versions.

HTH,
TC
 
You could try simply setting the Parent of the Access form's hWnd(via
the SetParent API) equal to the Word App window but that could lead to
problems if the user closed the Word app before Access.
For what the OP wants to accomplish I would suggest since they already
have an instance of the active word app they use Automation and have
Word popup the desired MessageBox.

--

HTH
Stephen Lebans
http://www.lebans.com
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.
 
Yes, nice solution!

TC


Stephen Lebans said:
You could try simply setting the Parent of the Access form's hWnd(via
the SetParent API) equal to the Word App window but that could lead to
problems if the user closed the Word app before Access.
For what the OP wants to accomplish I would suggest since they already
have an instance of the active word app they use Automation and have
Word popup the desired MessageBox.

--

HTH
Stephen Lebans
http://www.lebans.com
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.
 
What you can do is move the
WordApp.Visible = True

To "after" the msgbox command.

However, this means that word will not yet have appeared. However, you
really don't have a choice here, as you MUST bring ms-access to the front
again to show the msg command. You are not going to get "just" the msgbox
anyway, and thus all of ms-access will show.

So, I would just move the WordApp.Visible to right "after" the msgbox, and
you should be fine.

Also, as side note, that example code uses:

AppActivate "Microsoft Word"

You should replace the above with:

wordApp.Activate
wordApp.WindowState = 0 'wdWindowStateRestore

I recognize my word merge code here, and I have since changed the above,
since if you upgrade to word2000 or latter , then the title window changes
on you all the time, and your code will break. So, my wordmerge example code
now always uses the 2nd example to active word, as then the title bar name
does mess things up (now that word appears multiple times in the task bar,
and part of the document name is the application name now).
 
Back
Top