How can I bring the results of a query into the vba world??
For years I have used a connection string. So I tell the .mdb to connect to itself. This ALMOST always works. But about one out of every 400 times, problems happen.
Is there another way to get the results of a query?? Here is a code sample:
For years I have used a connection string. So I tell the .mdb to connect to itself. This ALMOST always works. But about one out of every 400 times, problems happen.
Is there another way to get the results of a query?? Here is a code sample:
Code:
Public Function test()
'Create some objects and primitives.
Dim rs As New ADODB.Recordset
Dim localConn As New ADODB.Connection
Dim counter As Integer
counter = 0
Dim allComments As String
allComments = ""
'Open the LOCAL connection.
localConn.Open "Provider = Microsoft.Jet.OLEDB.4.0; Data Source=C:\acmeSales\sales1.mdb; Jet OLEDB:System database=C:\acmeSales\acme.mdw; User ID=Admin;Password=j@w123"
'Configure the recordset object, and fill it with records.
With rs
.ActiveConnection = localConn
.CursorType = adOpenStatic
.LockType = adLockReadOnly
.Open "Select comments from salesTbl"
End With
'Iterate through the recordset building a string.
Do While counter < rs.RecordCount
allComments = allComments & ", " & rs(0).value
rs.Move 1
counter = counter + 1
Loop
'Display the string
MsgBox allComments
'Clean up
localConn.Close
End Function