Mark Simms
marksimms at verizon.net
Mon Oct 4 09:20:22 CDT 2010
Bill - here's a module-level function (CloseWordDocs) I called before doing a mail merge. The secret could be the Activate and/or Visible property settings. I do know that it kept Word "on top" after the merge was completed. Bottomline: I called this right before performing the merge. It's purpose was to "clean-up" any merge-type of Word documents still left open by the user. gAppWord is a global variable set to the handle of the word application. Right after the merge, I do this : gAppWord.Activate ' Re-focus on the Word App gAppWord.ScreenUpdating = True gAppWord.WindowState = wdWindowStateMaximize gAppWord.ActiveDocument.Activate ' This removes any open Word documents Public Sub CloseWordDocs(ByVal bCloseTemplate As Boolean, Optional ByVal bQuitWord As Boolean = False) Dim i As Long, cnt As Long Dim oMainDoc As Word.Document If Not gAppWord Is Nothing Then On Error Resume Next gAppWord.Visible = True End If If Err.Number <> 0 Or gAppWord Is Nothing Then On Error Resume Next Set gAppWord = GetObject(, "Word.Application") If Err.Number = 0 Then On Error Resume Next gAppWord.Visible = True If Err.Number = 0 Then gAppWord.Activate gAppWord.WindowState = wdWindowStateMinimize Else Exit Sub ' Word is not open, so exit immediately End If Else Exit Sub End If End If On Error GoTo Err With gAppWord Select Case .Documents.Count Case Is = 0 Case Else For Each oMainDoc In .Documents oMainDoc.Activate If bCloseTemplate Then On Error Resume Next ' required since not all docs have mailmerge fields ! cnt = oMainDoc.MailMerge.Fields.Count If Err.Number <> 0 And cnt > 0 Then oMainDoc.Close False End If On Error GoTo Err Else oMainDoc.Close True End If Next If bQuitWord Then .Quit Set gAppWord = Nothing End If End Select End With Exit Sub Err: MsgBox "Error in CloseWordDocs:" & Err.Number & " " & Err.Description, vbCritical, APPTITLE Set gAppWord = Nothing ' seems to be required End Sub > -----Original Message----- > From: accessd-bounces at databaseadvisors.com > [mailto:accessd-bounces at databaseadvisors.com] On Behalf Of > Bill Marriott > Sent: Monday, October 04, 2010 4:06 AM > To: Access Developers discussion and problem solving > Subject: Re: [AccessD] Doc Merge from Access > > Yes Charlotte I tried that to no avail. > I ran the debugger and there did not appear to be any more > code running in Access after the DoCmd.RunCommand > acCmdAppMinimize However Access keeps popping up in my face > like a recalcitrant Jack in the Box when it should stay minimized? > > Bill > > On Mon, Oct 4, 2010 at 3:52 AM, Charlotte Foust > <charlotte.foust at gmail.com>wrote: > > > Just as SWAG but I suspect the problem is that when you > click on the > > Word Doc, the Access window is no longer the active window, > so you're > > spinning your wheels. Have you tried using the RunCommand > to minimize > > before you follow the link (which I presume is to the Word doc)? > > > > Charlotte Foust > > > > On Sat, Oct 2, 2010 at 7:13 PM, Bill Marriott > > <bill.marriott09 at gmail.com> > > wrote: > > >> > > >> Hi Group, > > >> > > > > > > I am running Access 2010 on Win 7 > > > I would like the user to click on a hyperlink to open the > > > appropriate app with the correct file and have the Access > minimized > > > while the user can > > view > > > the hyperlinked file. > > > > > > The following code works but after minimizing the Access App' for > > > only a second and opening up Word with the correct file > Access opens > > > up again on top. > > > > > > Private Sub txtCV_Click() > > > If Not IsNull(Me.txtCV) Then > > > 'ActiveWindow.WindowState = wdWindowStateMinimise > 'tried this and > > > FollowHyperlink Me![txtCV], , True > > > DoCmd.RunCommand acCmdAppMinimize > 'tried this as > > > well > > > End If > > > End Sub > > > > > > Does anyone know why? > > > > > > thanks > > > > > > Bill > > > -- > > > AccessD mailing list > > > AccessD at databaseadvisors.com > > > http://databaseadvisors.com/mailman/listinfo/accessd > > > Website: http://www.databaseadvisors.com > > > > > > > -- > > AccessD mailing list > > AccessD at databaseadvisors.com > > http://databaseadvisors.com/mailman/listinfo/accessd > > Website: http://www.databaseadvisors.com > > > -- > AccessD mailing list > AccessD at databaseadvisors.com > http://databaseadvisors.com/mailman/listinfo/accessd > Website: http://www.databaseadvisors.com >