John Ruff
papparuff at comcast.net
Sat Aug 26 20:07:48 CDT 2006
After you create the WordObj set its visible property to true ' Shows this instance of Word WordObj.Visible = True papparuff -----Original Message----- From: accessd-bounces at databaseadvisors.com [mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Rocky Smolin - Beach Access Software Sent: Saturday, August 26, 2006 4:26 PM To: Access Developers discussion and problem solving Subject: Re: [AccessD] Word Window On Top Well, I'm really crappin' out with this guy. .Activate didn't work, nor .Show. He tests to see if word is already open - doesn't want to open a second instance. Set WordObj = GetObject(, "Word.Application") If Err.Number <> 0 Then Set WordObj = CreateObject("Word.Application") End If Nothing works so far when Word is already open. But I can't help but think there's a simple property or method (there's so freakin' many of 'em) to make Word the active window when you open a new document and word is already open. Any other ideas anybody? MTIA Rocky Heenan, Lambert wrote: > Rocky, > > WordObj needs to be declared As Word.Application, but is has to be in the > same scope as the function you are using. Notice that I actually declare the > xlObj inside my function. > > Lambert (first name) > > -----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 4:03 PM > To: Access Developers discussion and problem solving > 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