Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Excel Automation - Data Query HowTo
Message
De
23/04/2003 07:16:16
 
 
À
23/04/2003 05:55:56
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
Information générale
Forum:
Visual FoxPro
Catégorie:
COM/DCOM et OLE Automation
Divers
Thread ID:
00780265
Message ID:
00780521
Vues:
9
Thank you very much, Cetin. This helped me out a great deal!

>>Can anybody help me understand how to 'translate' a piece of VB code recorded in Excel into VFP usable code? I have some experience with this, but not as complex as this...
>>
>>The code below is what I start with... I know that I lose the SUB statement, replace the continuation character (_) with the VFP (;) character, the & with the + etc., but I keep getting a "missing ending )" error.
>>
>>Where might I look for further guidance on this?
>>
>>Thanks in advance for any help!
>>
>>Andrew
>>
>>Sub QueryTable()
>>'
>>' QueryTable Macro
>>' Macro recorded 22/04/2003 by Andrew Jennings
>>'
>>
>>'
>> With ActiveSheet.QueryTables.Add(Connection:= _
>> "ODBC;DSN=Visual FoxPro Tables;UID=;PWD=;SourceDB=f:\data\tssimms;SourceType=DBF;Exclusive=No;BackgroundFetch=Yes;Collate=Machine;" _
>> , Destination:=Range("A13"))
>> .CommandText = Array( _
>> "SELECT simhisn.line_no, simhisn.batch_no, simhisn.b_l, simhisn.pro_no" & Chr(13) & "" & Chr(10) & "FROM simhisn simhisn" & Chr(13) & "" & Chr(10) & "WHERE (simhisn.batch_no=$485)" & Chr(13) & "" & Chr(10) & "ORDER BY simhisn.line_no" _
>> )
>> .Name = "Query from Visual FoxPro Tables"
>> .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
>>End Sub
>
>Andrew,
>I think you're misinterpreting the CRLF there. I copied orders table to a free table version and this worked for me :
>Note that commandtext version still works, only comented to show you could directly use QueryTables.Add() method's 3rd parameter for SQL.
>
>#define xlInsertDeleteCells  1
>oExcel=Createobject('Excel.Application')
>With oExcel
>  .Visible = .T.
>  .Workbooks.Add
>  With .ActiveWorkBook.ActiveSheet.QueryTables.Add(;
>    "ODBC;DSN=Visual FoxPro Tables;"+;
>    "SourceDB=c:\mytestpath;"+;
>      "SourceType=DBF;Exclusive=No;BackgroundFetch=Yes;"+;
>      "Collate=Machine;", oExcel.ActiveWorkbook.ActiveSheet.Range("A13"),;
>      "SELECT OrdersFree.order_id, OrdersFree.cust_id, "+;
>      "OrdersFree.emp_id, OrdersFree.to_name,"+;
>      "OrdersFree.to_address, OrdersFree.to_city,"+;
>      "OrdersFree.to_region, OrdersFree.postalcode,"+;
>      "OrdersFree.to_country"+;
>      "  FROM OrdersFree"+;
>      "  WHERE OrdersFree.to_country = 'Germany'"+;
>      "  ORDER BY OrdersFree.emp_id")
>
>*!*	    .CommandText = ;
>*!*	      "SELECT OrdersFree.order_id, OrdersFree.cust_id, "+;
>*!*	      "OrdersFree.emp_id, OrdersFree.to_name,"+;
>*!*	      "OrdersFree.to_address, OrdersFree.to_city,"+;
>*!*	      "OrdersFree.to_region, OrdersFree.postalcode,"+;
>*!*	      "OrdersFree.to_country"+;
>*!*	      "  FROM OrdersFree"+;
>*!*	      "  WHERE OrdersFree.to_country = 'Germany'"+;
>*!*	      "  ORDER BY OrdersFree.emp_id"
>
>    .Name = "Query from Visual FoxPro Tables"
>    .FieldNames = .T.
>    .RowNumbers = .F.
>    .FillAdjacentFormulas = .F.
>    .PreserveFormatting = .T.
>    .RefreshOnFileOpen = .F.
>    .BackgroundQuery = .T.
>    .RefreshStyle = xlInsertDeleteCells
>    .SavePassword = .T.
>    .SaveData = .T.
>    .AdjustColumnWidth = .T.
>    .RefreshPeriod = 0
>    .PreserveColumnInfo = .T.
>    .Refresh(.F.)
>  Endwith
>  .Visible = .T.
>Endwith
>
>PS: With single tables you might drop aliases from fieldnames to shorten the SQl string (or use shorter aliases).
>Cetin
On a CLEAR day you can see forever.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform