One of my first attempts at VBA:
Option Compare Database
Function Vendors()
Dim CurComm As New ADODB.Connection
Dim RS As New ADODB.Recordset
Dim VendorID
Dim i
Set curDB = CurrentDb
Set CurrConn = New ADODB.Connection
With CurConn
.Provider = "Microsoft.Jet.OLEDB.4.0"
.ConnectionString = "datasource=" & curDB.Name
End With
Set RS = New ADODB.Recordset
RS.CursorType = adOpenDynamic
RS.LockType = adLockOptimistic
RS.Open "Select * From INVUPC;", CurConn, , , adCmdText
i = 0
Do Until RS.EOF
For Each VENDOR In RS.Fields
VendorID(i) = VENDOR.Value
i = i + 1
Next
RS.MoveNext
Loop
RS.Close
CurConn.Close
End Function
What I want to do next is to create a loop to get result sets in a select format kinda like this:
SELECT Vendor, UPC from INVUPC WHERE Vendor=(VendorID from above loop) and output these results to seperate tables.
Any help would be great.
Option Compare Database
Function Vendors()
Dim CurComm As New ADODB.Connection
Dim RS As New ADODB.Recordset
Dim VendorID
Dim i
Set curDB = CurrentDb
Set CurrConn = New ADODB.Connection
With CurConn
.Provider = "Microsoft.Jet.OLEDB.4.0"
.ConnectionString = "datasource=" & curDB.Name
End With
Set RS = New ADODB.Recordset
RS.CursorType = adOpenDynamic
RS.LockType = adLockOptimistic
RS.Open "Select * From INVUPC;", CurConn, , , adCmdText
i = 0
Do Until RS.EOF
For Each VENDOR In RS.Fields
VendorID(i) = VENDOR.Value
i = i + 1
Next
RS.MoveNext
Loop
RS.Close
CurConn.Close
End Function
What I want to do next is to create a loop to get result sets in a select format kinda like this:
SELECT Vendor, UPC from INVUPC WHERE Vendor=(VendorID from above loop) and output these results to seperate tables.
Any help would be great.