NigelShaw
Registered User.
- Local time
- Today, 15:15
- Joined
- Jan 11, 2008
- Messages
- 1,575
Hi
another adodb question
i can open a recordset created with a sql string using DAO quite easily by using the OpenQuery and / or runSQL method but how can i do this when i collect a recordset using ADODB?
i tried using the same options but i get nothing.
here is my code for opening the connection and collecting the recordset so far
help appreciated as usual
Nidge
another adodb question

i can open a recordset created with a sql string using DAO quite easily by using the OpenQuery and / or runSQL method but how can i do this when i collect a recordset using ADODB?
i tried using the same options but i get nothing.
here is my code for opening the connection and collecting the recordset so far
Code:
Sub SQLCollectData()
'##set up your variables##
Dim m_oRecordset As ADODB.Recordset
Dim m_sConnStr As String
Dim sSQL As String
Dim oConnection1 As ADODB.Connection
Dim strSource As String
Dim strSourceEnviron As String
Dim strSourceServer As String
Dim strCatalog As String
'##collect environment data##
strSourceEnviron = VBA.Environ("computername")
strSourceServer = "\CMJ"
strSource = strSourceEnviron & strSourceServer
strCatalog = "SalonIris"
'##create connection to SQL server##
m_sConnStr = "Provider='SQLOLEDB';Data Source='" & strSource & "';" & _
"Initial Catalog='" & strCatalog & "';Integrated Security='SSPI';"
Set oConnection1 = New ADODB.Connection
oConnection1.CursorLocation = adUseClient
oConnection1.Open m_sConnStr
'##Create specific SQL statement##
'sSQL = "SELECT fldFirstName, fldLastName, fldActive " & _
'"FROM tblEmployees WHERE fldActive = 1"
'##Create specific SQL statement##
sSQL = "SELECT fldFirstName, fldLastName, fldDateScheduled, fldCheckedIn, fldCNClosed " & _
"FROM tblTicketsSummary WHERE fldCheckedIn <> 0"
'##Run SQL##
Set m_oRecordset = New ADODB.Recordset
m_oRecordset.Open sSQL, oConnection1, adOpenStatic, _
adLockBatchOptimistic, adCmdText
m_oRecordset.MarshalOptions = adMarshalModifiedOnly
Set m_oRecordset.ActiveConnection = Nothing
'##count records for testing##
With m_oRecordset
j = .RecordCount
MsgBox j
'##Set up loop through records##
For i = 1 To j
'##collect data from table or query##
strGetData = !fldFirstName
strGetData = strGetData & " " & !fldLastName
'MsgBox strGetData
.MoveNext
Next i
End With
'##clean up##
m_oRecordset.Close
oConnection1.Close
Set m_oRecordset = Nothing
Set oConnection1 = Nothing
Exit Sub
End Sub
help appreciated as usual

Nidge