Advertisement

01.18.2007 at 09:01AM PST, ID: 22127633
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.4

Send a Recordset as Excel file via DoCmd.SendObject

Asked by SWRO in Microsoft Access Database

Tags: ,

Hello,

Is it even possible to use the Recordset as part of the DoCmd.SendObject method?

I have a recordset that returns some rows. I check that recordset to make sure that the rowcount > 0. If so, I want the rows output to Excel and sent to a user.

doing a docmd.sendobject acSendTable, recordsetname, etc, etc, etc  does not work. Nor does using acSendQuery. Nor does using either of those with the actual SQL string that populates the recordset.

Here's my code....

'// Refresh the form
Form.Refresh

'// Check to see if there is a value in the txtCloseLocationAgentNumber field
'// If not, let the user know and exit this Sub
Dim strAgentNumberClose As String
strAgentNumberClose = txtCloseLocationAgentNumber.Value
If strAgentNumberClose = Null Or strAgentNumberClose = "" Then
    MsgBox "The Agent # field is blank"
    Exit Sub
End If

Dim strSQL As String
strSQL = "SELECT tblU778.DateCreation AS [CREATION DATE]," _
& "tblU778.EffectiveDateOfChange AS [DATE OF CHANGE]," _
& "tblRegion.RO AS REGION," _
& " tblU778.CloseLocationAgentNumber AS [AGENT NUMBER]," _
& "tblRegion.NAME," _
& "tblRegion.LASTNAME AS [AGENT LAST NAME]," _
& "tblRegion.FIRSTNAME AS [AGENT FIRST NAME]," _
& "tblRegion.STATE & tblregion.loc AS [BUILDING CODE]," _
& "tblRegion.AGTTYPE AS [AGENT TYPE]," _
& "tblRegion.AGSTATUS AS [AGENT STATUS]," _
& "tblRegion.ADDRESS AS ADDRESS," _
& "tblRegion.CITY AS CITY," _
& "tblRegion.STATE AS STATE," _
& "tblRegion.ZIP AS ZIP," _
& "tblRegion.PHONE AS [PHONE NUMBER]," _
& "tblRegion.MARKET," _
& "tblRegion.TERR AS TERRITORY," _
& "tblRegion.EMPDT AS [AGENT HIRE DATE]," _
& "tblU778.CloseLocationAgentTermDate AS [TERMINATION DATE], ""A0"" & tblu778.CloseLocationAgentNumber & ""@anywhere.com"" AS EMail," _
& "'' AS [FAX NUMBER]," _
& "'No' AS [NAE ELIGIBILITY]," _
& "'' AS [TELEPHONE PROVIDER]" _
& "FROM tblU778 INNER JOIN tblRegion ON tblU778.CloseLocationAgentNumber = tblRegion.AGTNUM " _
& "WHERE tblU778.U778ID= '" & Me.txtU778ID.Value & "'" _
& "ORDER BY tblU778.DateCreation DESC;"

'// Declare a recordset to get the output of the query
Dim rst As New ADODB.Recordset
Dim lngRecords As Long
rst.Open strSQL, CurrentProject.Connection, adOpenStatic, adLockReadOnly
Do Until rst.EOF
 'Debug.Print "Looping"
 rst.MoveNext
Loop


'// See how many records are in the recordset
lngRecords = rst.RecordCount
MsgBox "There are " & lngRecords & " records"
If lngRecords = 0 Then

>>>THIS IS THE PROBLEM AREA
DoCmd.SendObject acSendTable, strSQL, "MicrosoftExcelBiff8(*.xls)", "john.doe@anywhere.com", , , "Anywhere Update for Agent Number:" & strAgentNumberClose, "Attached is an Anyone file. Any questions, please let us know.", False, ""
chkKetchumNotifiedTerm.Value = True
MsgBox "Ketchum has been notified of the term of Agent Number " & strAgentNumberClose
Form.Requery
Else
    MsgBox "Your query found Zero records! Check to make sure that this Agent # exists in Table1"
    Exit Sub
End If

Any help that you could provide would be greatly appreciated.Start Free Trial
[+][-]01.18.2007 at 09:02AM PST, ID: 18342667

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01.18.2007 at 09:08AM PST, ID: 18342740

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01.18.2007 at 09:38AM PST, ID: 18343021

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01.19.2007 at 08:37AM PST, ID: 18350369

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]01.19.2007 at 09:01AM PST, ID: 18350627

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Microsoft Access Database
Tags: excel, recordset
Sign Up Now!
Solution Provided By: jefftwilley
Participating Experts: 2
Solution Grade: A
 
 
[+][-]01.25.2007 at 01:56PM PST, ID: 18399733

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32