DoCmd.SendObject object assistance needed... [modified]
-
Hi, guys. I really need some assistance with the DoCmd.SendObject object in VBA in Microsoft Access. It appears that I am only limited to specific ObjectTypes that does not include an approach to do so dynamically in code. It appears in code that there are fewer options than there are with the implementation of macros which also permit "Stored Procedures" and "Server Views". Can I send the results of strSQLFQT to the SendObject? You see, I need to loop through two tables at the same time, and for every occurrence of the DISTINCT item in rstMRL there could be many records in rstFQT. I would like to send only the relevent records from rstFQT to each person in rstMRL. Can someone kindly tell me where I am going wrong. The code I have so far is as follows:
Option Compare Database
Dim db As New DAO.DBEngine
Dim rec As RecordsetFunction Email_New()
On Error GoTo Email_New_ErrDoCmd.OpenQuery "Final Query Test 2", acViewNormal, acReadOnly DoCmd.GoToRecord acQuery, "Final Query Test 2", acFirst Call SendEmails
Email_New_Exit:
Exit FunctionEmail_New_Err:
MsgBox Error$
Resume Email_New_ExitEnd Function
Function SendEmails()
On Error GoTo ErrorHandlerDim Cnxn As ADODB.Connection Dim strConn As String Dim rstMRL As ADODB.Recordset Dim cmdSQLMRL As ADODB.Command Dim strSQLMRL As String Dim rstFQT As ADODB.Recordset Dim cmdSQLFQT As ADODB.Command Dim strSQLFQT As String Dim strHoldRecString As String Dim strMessage As String Set Cnxn = New ADODB.Connection strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=J:\\GELCO DATABASE\\Gelco\_USA.mdb;" Cnxn.Open strConn Set cmdSQLMRL = New ADODB.Command Set cmdSQLMRL.ActiveConnection = Cnxn strSQLMRL = "Select \[Rep Number\], \[Rep ID\], \[Email Address\] " & \_ "FROM \[Master Rep List Test\] ORDER BY \[Rep Number\]" cmdSQLMRL.CommandType = adCmdUnknown cmdSQLMRL.CommandText = strSQLMRL Set rstMRL = cmdSQLMRL.Execute() rstMRL.MoveFirst strHoldRecString = rstMRL!\[Rep Number\] Set cmdSQLFQT = New ADODB.Command Set cmdSQLFQT.ActiveConnection = Cnxn ' Attempted Dynamic SQL here... strSQLFQT = "SELECT \[Confirmation #\], \[Rep Name\], " & \_ "\[Report #\], \[Email Address\], \[Days Aged\] " & \_ "FROM \[Final Query Test 2\] WHERE \[Days Aged\] > 30 " & \_ "AND \[Rep ID2\] = '" & strHoldRecString & "'" MsgBox strSQLFQT ' Shows the results cmdSQLF