[AccessD] Word Window On Top

Rocky Smolin - Beach Access Software bchacc at san.rr.com
Wed Aug 23 19:10:38 CDT 2006


Don't know.  I'll forward to the client and see.  When I try it Word 
always pops up on top.  He tests for Word being open before creating  
the object I think it may be that if Word is already open it doesn't end 
up on top.

I'll report back.

Rocky


Michael R Mattys wrote:
> Rocky,
>
>   
>> Dim WordObj As Word.Application
>>     
>
> Doesn't WordObj.Activate work?
>
> Michael R. Mattys
> MapPoint Developer
> www.mattysconsulting.com
>
> ----- Original Message ----- 
> From: "Rocky Smolin - Beach Access Software" <bchacc at san.rr.com>
> To: "Access Developers discussion and problem solving" 
> <accessd at databaseadvisors.com>
> Sent: Wednesday, August 23, 2006 4:03 PM
> Subject: Re: [AccessD] Word Window On Top
>
>
>   
>> Heenan:
>>
>> With WordObj declared as: Dim WordObj As Word.Application
>>
>> and the Function in a separate module, the statement SetForegroundWindow
>> WordObj.hWnd won't compile - gives a method or data member not found 
>> error.
>>
>> The Word 11.0 object library is checked in the references.
>>
>> I tried redeclaring WordObj as Object but that didn't work either.
>>
>> TIA
>>
>> Rocky
>>
>>
>> Heenan, Lambert wrote:
>>     
>>> Well here is how I do the same thing with Access opening Excel. It is all
>>> dependant on getting the handle of the Excel window (or Word window in 
>>> your
>>> case)...
>>>
>>> Public Declare Function SetForegroundWindow Lib "user32" (ByVal hWnd As
>>> Long) As Long
>>>
>>> Sub ViewInExcel(strRecordSource As String, Optional bFormatColumns As
>>> Boolean = True)
>>> '---------------------------------------------------------------------------
>>> ------------
>>> ' Procedure : ViewInExcel
>>> '
>>> ' Purpose   : Displays a recordset (Table or query) in an Excel 
>>> worksheet,
>>> but does
>>> '           : not save the Excel file. The user can choose to save the 
>>> file
>>> if needed.
>>> '---------------------------------------------------------------------------
>>> ------------
>>> '
>>> Dim objXL As excel.Application
>>> Dim objSheet As excel.Worksheet
>>> Dim objWB As excel.Workbook
>>> Dim rs As Object
>>> Dim oRng As excel.Range
>>> Dim nCols As Long, n As Long
>>>
>>>     Set rs = CurrentDb.OpenRecordset(strRecordSource)
>>>     nCols = rs.Fields.Count
>>>     Set objXL = CreateObject("Excel.Application")
>>>     objXL.SheetsInNewWorkbook = 1
>>>     Set objWB = objXL.Workbooks.Add
>>>     Dim f As Field
>>>     n = 0
>>>     ' CopyFromRecordset does not bring the column headings with it.
>>>     ' So here we add them manually.
>>>     For Each f In rs.Fields
>>>         n = n + 1
>>>         objWB.Sheets("Sheet1").Cells(1, n) = f.Name
>>>     Next f
>>>     ' and now drop the data into row 2
>>>     objWB.Sheets("Sheet1").Cells(2, 1).CopyFromRecordset rs
>>>     If bFormatColumns Then
>>>         Set oRng = objWB.Sheets("Sheet1").Range(CStr(ExcelColumn(1)) & 
>>> "1:"
>>> & CStr(ExcelColumn(nCols)) & "1")
>>>         oRng.EntireColumn.AutoFit
>>>         oRng.Interior.Color = vbYellow
>>>         oRng.Borders.Color = vbBlack
>>>         Set oRng = Nothing
>>>     End If
>>>     rs.Close
>>>     Set rs = Nothing
>>>     objXL.Visible = True
>>>     SetForegroundWindow objXL.hWnd ' here's the line that brings the 
>>> window
>>> to the foreground.
>>> End Sub
>>>
>>> HTH
>>>
>>> Lambert
>>> -----Original Message-----
>>> From: accessd-bounces at databaseadvisors.com
>>> [mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Rocky Smolin -
>>> Beach Access Software
>>> Sent: Wednesday, August 23, 2006 1:33 PM
>>> To: Access Developers discussion and problem solving
>>> Subject: [AccessD] Word Window On Top
>>>
>>>
>>> Dear List:
>>>
>>> Using automation I open a word doc, but the access app is still on top.
>>> Word is in the tray.  Click it and the doc is there and open.  Q: how
>>> can I give the word doc window the focus after I open it?
>>>
>>> MTIA
>>>
>>> Rocky
>>>
>>>
>>>       
>> -- 
>> Rocky Smolin
>> Beach Access Software
>> 858-259-4334
>> www.e-z-mrp.com
>>
>> -- 
>> AccessD mailing list
>> AccessD at databaseadvisors.com
>> http://databaseadvisors.com/mailman/listinfo/accessd
>> Website: http://www.databaseadvisors.com 
>>     
>
>   

-- 
Rocky Smolin
Beach Access Software
858-259-4334
www.e-z-mrp.com




More information about the AccessD mailing list