Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Initiate MSQUERY via VBA
Message
 
 
To
06/11/2005 00:30:13
Peter Wagner
Point Informática Ltda.
Limeira, Brazil
General information
Forum:
Visual FoxPro
Category:
COM/DCOM and OLE Automation
Environment versions
Visual FoxPro:
VFP 8 SP1
Database:
MS SQL Server
Miscellaneous
Thread ID:
01065797
Message ID:
01065799
Views:
17
This message has been marked as a message which has helped to the initial question of the thread.
See corrections in the code below

>Hi, Is there a way to initiate MSQUERY via VBA then capture the info on exiting so that I can insert the query results into a spreadsheet - also via VBA.
>
>My customer asked to use OLE Automation in the application to show the MS Query form.
>After building the query the user wants to see the data in a Excel spreadsheet.
>I tryed to use the macro that was recorded and see how I could automate the process, but I wasnt sucessfull because I havent found any way to initiate MSQUERY using OLE.
>The User just want to see the MS Query form and then return the result to excel.
>
>I also tried to call the .exe file directly from VFP (MSQRY32.EXE) but didnt find how to return the Select statement so I could use it in the OLE Automation.
>I can call MSQRY32.EXE, but can't find a way to get the SELECT statement to use in Excel.
>
>.CommandText = "SELECT Bancos.Codigo_banco, Bancos.Nome_banco, FROM Atuante.dbo.Bancos Bancos"
>
>The Excel macro:
<snip>>
>In VFP:
>
>LOCAL oExcel AS 'Excel.Application'
>oExcel = CREATEOBJECT('Excel.Application')
>oExcel.SheetsInNewWorkbook = 1
>oWorkbook = oExcel.Workbooks.ADD
>oActiveSheet = oExcel.ActiveSheet
>oActiveSheet.NAME = "teste"
>
>connstringx =  "ODBC;DSN=atuante;UID=XX;PWD=XX;Database=Atuante"
>
***
WITH oActiveSheet.QueryTables.ADD(connstringx,oActiveSheet.Range('A1'))
***
>	.NAME = "Contact List"
***
	.CommandText = "SELECT Bancos.Codigo_banco, Bancos.Nome_banco, Bancos.Numero_banco" + ;
             + Chr(13) + Chr(10) + "FROM Atuante.dbo.Bancos Bancos"
***
>	.FieldNames = .T.
>	.RowNumbers = .F.
>	.FillAdjacentFormulas = .F.
>	.PreserveFormatting = .T.
>	.RefreshOnFileOpen = .F.
>	.BackgroundQuery = .T.
>	.SavePassword = .T.
>	.SaveData = .T.
>	.AdjustColumnWidth = .T.
>	.RefreshPeriod = 0
>	.PreserveColumnInfo = .T.
***
	.REFRESH(.F.)
***
>ENDWITH
>oExcel.VISIBLE = .T.
>
>
>Any ideias how to get the SQLStatement ?
>
--sb--
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform