Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Initiate MSQUERY via VBA
Message
From
06/11/2005 00:30:13
Peter Wagner
Point Informática Ltda.
Limeira, Brazil
 
 
To
All
General information
Forum:
Visual FoxPro
Category:
COM/DCOM and OLE Automation
Title:
Initiate MSQUERY via VBA
Environment versions
Visual FoxPro:
VFP 8 SP1
Database:
MS SQL Server
Miscellaneous
Thread ID:
01065797
Message ID:
01065797
Views:
119
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:
With ActiveSheet.QueryTables.Add(Connection:=Array(Array( _
        "ODBC;DSN=Atuante;Description=conexão ao BD da atuante p/ gerar SP;UID=XX;PWD=XXX;APP=Microsoft® Query;WSID=BXXB;DATABASE=Atuante;LANG" _
        ), Array("UAGE=Português")), Destination:=Range("A1"))
        .CommandText = Array( _
        "SELECT Bancos.Codigo_banco, Bancos.Nome_banco, Bancos.Numero_banco" & Chr(13) & "" & Chr(10) & "FROM Atuante.dbo.Bancos Bancos" _
        )
        .Name = "Consulta de Atuante"
        .FieldNames = True
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .BackgroundQuery = True
        .RefreshStyle = xlInsertDeleteCells
        .SavePassword = True
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0
        .PreserveColumnInfo = True
        .Refresh BackgroundQuery:=False
    End With
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,'A1:A1')
	.NAME = "Contact List"
	.CommandText = "???  <<<<<<========== ???"
	.FieldNames = .T.
	.RowNumbers = .F.
	.FillAdjacentFormulas = .F.
	.PreserveFormatting = .T.
	.RefreshOnFileOpen = .F.
	.BackgroundQuery = .T.
	.SavePassword = .T.
	.SaveData = .T.
	.AdjustColumnWidth = .T.
	.RefreshPeriod = 0
	.PreserveColumnInfo = .T.
	.REFRESH BackgroundQuery = .F.
ENDWITH
oExcel.VISIBLE = .T.
Any ideias how to get the SQLStatement ?

Thanks in Advance

Peter
Next
Reply
Map
View

Click here to load this message in the networking platform