Enter code similar to the following example (providing your actual ID, password, selection criteria, and so on):
'This program will connect to the Siebel OLE DB Provider, retrieve data and save 'the records in a file with tab separated fields. Other tools can then be used to 'further process the data.
Dim Fso, File
'Setup program parameters.
ProviderString = "SiebelOLEDB.Provider.1"
DataSourceString = "siebel://MyGateway/MyEnterprise/MyObjMgr/MyServer"
UserIdString = "MyUserId"
PasswordString = "MyPassword"
OutFileString = "output.txt"
'Build the connection string.
ConnectString = "Provider=" & ProviderString & ";User Id=" & UserIdString & ";Password=" & PasswordString & ";Data Source=" & DataSourceString & ";"
'Ask the user if they are ready to establish a connection and retrieve the data.
Message = "Ready to connect using" & Chr(13) & Chr(10) & ConnectString & Chr(13) & Chr(10) & "Do you want to continue?"
Continue = MsgBox(Message, vbYesNo, "Ready to Connect")
If Continue = vbYes Then
'Create the output file for storing the data.
Set Fso = CreateObject("Scripting.FileSystemObject")
Set File = Fso.OpenTextFile(OutFileString, 2, True)
'Establish a connection.
Set Connection = CreateObject("ADODB.Connection")
Connection.Open ConnectString
'Execute a query to create a record set.
'Retrieve all accounts involved in any electrical related business.
QueryString = "Select * from Account_Account_1 where 'Line of Business' = 'Electrical*'"
Set RecordSet = Connection.Execute(QueryString)
'If there is any data then write a header record with column names.
If Not RecordSet.EOF Then
First = True
For Each Field in RecordSet.Fields
'Write each field within double quotes and a tab separator between them.
If First Then
File.Write """"
First = False
Else
File.Write """" & Chr(9) & """"
End If
File.Write Field.Name
Next
File.WriteLine """"
End If
'Keep track of the number of records.
RecordCount = 0
Do While Not RecordSet.EOF
First = True
For Each Field in RecordSet.Fields
'Write each field within double quotes and a tab separator between them.
If First Then
File.Write """"
First = False
Else
File.Write """" & Chr(9) & """"
End If
File.Write Field.Value
Next
File.WriteLine """"
RecordCount = RecordCount + 1
RecordSet.MoveNext
Loop
'Clean up local variables.
RecordSet.Close
Connection.Close
Set RecordSet = nothing
Set Connection = nothing
File.Close
Set File = nothing
Set Fso = nothing
'Notify the user of the number of records retrieved and stored.
Message = "Successfully retrieved and stored " & RecordCount & " records in " & OutFileString
MsgBox Message, vbOkOnly, "Data Retrieved"
End If