Lookout

cancel
Showing results for 
Search instead for 
Did you mean: 

Retrieving data from citadel into Excel using Excel macros Only..not microsoft query Analyzer

Sir,

subject:: Retrieving data from citadel from excel macro

Actually what i want is to retrieve data from citadel to excel having interval of 1 day...what the problem i am facing
is that i am using excel macro in which i am using sqlrequest to get the data into array , then i retrieve data from that array into excel sheet using lbound and unbound function of array......i am also sending my file plz go thro' it....when i request a query with * it returns the data to the excel sheet and all the fields are overlapping...not get data required......but get the data which is not understandable....but when i run a query with star(all fields) its run well...but when i query the data with the specific fields in citadel like localtime and utctime...it gives the error �subscript out of range..�run time error 9..its the error of array dynamically generated...but when i convert the citadel database into excess ..and then retrieve that data into excel using same code it works fine with specific fields and conditions but it fails with the citadel database...i have the requirement with the citadel database..plz help out me...I want to use only
excel macro as it runs automatically when we want like when we open the excel sheet it works whereas with the Microsoft query my requirement works fine�plz let me know if u have solution with excel macro only�


my code as follows...
Private databaseName As Variant
Dim returnArray As Variant
Private queryString As Variant
Dim strText As String

Private Sub Worksheet_Activate()
databaseName = "CITADEL4"
queryString = "SELECT * FROM Traces WHERE interval=1:04:00"
MsgBox queryString
returnArray = SQLREQUEST("DSN=Citadel4", queryString, Worksheets("Sheet1").Range("A1"), 2, True)
For i = LBound(returnArray, 1) To UBound(returnArray, 1)
For j = LBound(returnArray, 2) To UBound(returnArray, 2)
Worksheets("Sheet1").Cells (i, j).Formula = returnArray(i, j)
'MsgBox j
Next j
Next i
End Sub

What I want is the query this one�
�Select Localtime, utctime, Resolution from traces where localtime >11/7 6:00 and localtime<11/7 18:00 and interval=1:00:00� �
the code which I wanted to run is as follows but it fails �giving error subscript out of range but works well with all fields not the specific fields required�

Private databaseName As Variant
Dim returnArray As Variant
Private queryString As Variant
Dim strText As String
Private Sub Worksheet_Activate()
databaseName = "CITADEL4"
queryString = "�Select Localtime , utctime ,Resolution from traces where localtime >11/7 6:00 and localtime<11/7 18:00 and interval=1:00:00� �
returnArray = SQLREQUEST("DSN=Citadel4", queryString, Worksheets("Sheet1").Range("A1"), 2, True)
For i = LBound(returnArray, 1) To UBound(returnArray,1)
For j = LBound(returnArray, 2) To UBound
(returnArray, 2)
Worksheets("Sheet1").Cells(i, j).Formula = returnArray(i, j)
Next j
Next i
End Sub

Plz help me out �

Sukesh puri
sukeshpuri@hotmail.com
sukeshpuri@yahoo.com
SPRAY ENGG. DEVICES CHANDIGARH
0 Kudos
Message 1 of 2
(3,157 Views)
Sukesh,
The best source is refering the Lookout help. Go to Help>Content and then there is section on Structured Querry Language along with some examples of accessing Citadel data. Also there is a tutorial on accessing data in from different programs: http://zone.ni.com/devzone/conceptd.nsf/webmain/B5225714C33F1BD586256808007406A7?opendocument

Now to your querry I recommend still using MS Querry. It is easy to construct the querries and verify that you are getting the right data. In your case you do not want to use MS Querry for the final implementation, but once you have a good querry in MS Querry you can go to View>SQL and it will display the SQL querry. You can use that querry in your macro.

Carl L
National Instruments
0 Kudos
Message 2 of 2
(3,157 Views)