I have created a module that I can get to run when running it from VBA but when I reference the module in a macro using either the OpenModule AssignBrokers or RunCode AssignBrokers() -- the module doesn't work correctly. Any clues? Below is the module code that is being run.
Public Sub AssignBrokers()
Dim rstLeads As ADODB.Recordset
Dim rstBrokers As ADODB.Recordset
Set rstLeads = New ADODB.Recordset
Set rstLeads.ActiveConnection = CurrentProject.Connection
rstLeads.CursorType = adOpenKeyset
rstLeads.LockType = adLockOptimistic
rstLeads.Source = "tblImportedRecords"
rstLeads.Open Options:=adCmdTableDirect
Set rstBrokers = New ADODB.Recordset
rstBrokers.Open "SELECT BrokerCode FROM tblBrokers WHERE ActiveBroker=true", CurrentProject.Connection
While Not rstLeads.EOF
If (rstBrokers.EOF) Then
rstBrokers.MoveFirst
End If
rstLeads!BrokerCode = rstBrokers!BrokerCode
rstLeads.Update
rstBrokers.MoveNext
rstLeads.MoveNext
Wend
rstLeads.Close
rstBrokers.Close
Set rstLeads = Nothing
Set rstBrokers = Nothing
End Sub
Public Sub AssignBrokers()
Dim rstLeads As ADODB.Recordset
Dim rstBrokers As ADODB.Recordset
Set rstLeads = New ADODB.Recordset
Set rstLeads.ActiveConnection = CurrentProject.Connection
rstLeads.CursorType = adOpenKeyset
rstLeads.LockType = adLockOptimistic
rstLeads.Source = "tblImportedRecords"
rstLeads.Open Options:=adCmdTableDirect
Set rstBrokers = New ADODB.Recordset
rstBrokers.Open "SELECT BrokerCode FROM tblBrokers WHERE ActiveBroker=true", CurrentProject.Connection
While Not rstLeads.EOF
If (rstBrokers.EOF) Then
rstBrokers.MoveFirst
End If
rstLeads!BrokerCode = rstBrokers!BrokerCode
rstLeads.Update
rstBrokers.MoveNext
rstLeads.MoveNext
Wend
rstLeads.Close
rstBrokers.Close
Set rstLeads = Nothing
Set rstBrokers = Nothing
End Sub