PC Review


Reply
Thread Tools Rate Thread

Send a Table with Filters. HELP!

 
 
TheNovice
Guest
Posts: n/a
 
      2nd Apr 2008
Good morning all,

I have a quick Question. I need to send a table out in Excel, I have the
code set up but I need to filter it out to equal what is on the table.

I am recycling some old code that uses a report but the format is not what
we are looking for.

Here is a sample of the code: can someone PLEASE HELP!

Private Sub Form_Open(Cancel As Integer)
Dim db As Database
Set db = CurrentDb
Dim rc As Recordset
Dim stToName As String
Dim strRSM As String
Dim strSubj As String
Dim strBody As String
Dim strFileName As String
Dim rpt As TableDef

DoCmd.SetWarnings False
DoCmd.OpenQuery "qryWinFull"
DoCmd.OpenQuery "qryWinFullTable"
DoCmd.SetWarnings True
'DoCmd.OpenQuery "WinFull", acViewDesign
'DoCmd.OpenTable Winfull, acViewNormal, acEdit
'Set rpt = Table!Winfull
'rpt.Visible = False

Set rc = db.OpenRecordset("RSM Table")
If Not (rc.BOF Or rc.EOF) Then
rc.MoveFirst
Do Until rc.EOF
stToName = rc!emailid
strSubj = "Tomorrow's orders within 20% of Full Pallet"
strBody = "Please find the Enclosed Report for Tomorrow's orders
within 20% of Full Pallet"
strRSM = rc![CMRSM#]
strFileName = "c:\commun\Within 20 Percent of Pallet for " +
strRSM + ".xls"
BuildExcelSht stToName, strSubj, strBody, strFileName, strRSM
'Set rpt = Table!Winfull
rc.MoveNext
Loop
End If
DoCmd.SetWarnings False
DoCmd.Close acQuery, "qryWinFullTable"
Exit Sub


End Sub

Sub BuildExcelSht(stToName As String, strSubj As String, strBody As String,
strFileName As String, strRSM As String)

'rpt.Filter = "RGN = " & Chr(34) & stDSM & Chr(34)
'DoCmd.SendObject acReport, stDocName, "Snapshot Format", stToName,
stCCName, , stSubjLine, stBody, False
DoCmd.OutputTo acOutputTable, "Winfull", "Microsoft Excel", strFileName

Set objEmail = CreateObject("CDO.Message")
objEmail.From = "(E-Mail Removed)"
objEmail.To = stToName
'objEmail.Cc = stCCName
objEmail.Subject = stSubjLine
objEmail.Textbody = stBody
objEmail.AddAttachment strFileName
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") =
"xxxxxx.xxxxx.com"
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objEmail.Configuration.Fields.Update
objEmail.Send


Exit Sub


End Sub


--
-The Novice
Learn Today, Teach Tomorrow

Great Success is ones ability to ask for Help.
 
Reply With Quote
 
 
 
 
Jeff Boyce
Guest
Posts: n/a
 
      2nd Apr 2008
I'm not clear on something.

I thought you needed to send out a set of data (table or otherwise).

A common approach to doing this is to create a query that returns what you
want to export, then export that query (actually, when you do the Export,
only the data goes.)

Regards

Jeff Boyce
Microsoft Office/Access MVP

"TheNovice" <(E-Mail Removed)> wrote in message
news:B1688B08-0015-45CF-9762-(E-Mail Removed)...
> Good morning all,
>
> I have a quick Question. I need to send a table out in Excel, I have the
> code set up but I need to filter it out to equal what is on the table.
>
> I am recycling some old code that uses a report but the format is not what
> we are looking for.
>
> Here is a sample of the code: can someone PLEASE HELP!
>
> Private Sub Form_Open(Cancel As Integer)
> Dim db As Database
> Set db = CurrentDb
> Dim rc As Recordset
> Dim stToName As String
> Dim strRSM As String
> Dim strSubj As String
> Dim strBody As String
> Dim strFileName As String
> Dim rpt As TableDef
>
> DoCmd.SetWarnings False
> DoCmd.OpenQuery "qryWinFull"
> DoCmd.OpenQuery "qryWinFullTable"
> DoCmd.SetWarnings True
> 'DoCmd.OpenQuery "WinFull", acViewDesign
> 'DoCmd.OpenTable Winfull, acViewNormal, acEdit
> 'Set rpt = Table!Winfull
> 'rpt.Visible = False
>
> Set rc = db.OpenRecordset("RSM Table")
> If Not (rc.BOF Or rc.EOF) Then
> rc.MoveFirst
> Do Until rc.EOF
> stToName = rc!emailid
> strSubj = "Tomorrow's orders within 20% of Full Pallet"
> strBody = "Please find the Enclosed Report for Tomorrow's
> orders
> within 20% of Full Pallet"
> strRSM = rc![CMRSM#]
> strFileName = "c:\commun\Within 20 Percent of Pallet for " +
> strRSM + ".xls"
> BuildExcelSht stToName, strSubj, strBody, strFileName, strRSM
> 'Set rpt = Table!Winfull
> rc.MoveNext
> Loop
> End If
> DoCmd.SetWarnings False
> DoCmd.Close acQuery, "qryWinFullTable"
> Exit Sub
>
>
> End Sub
>
> Sub BuildExcelSht(stToName As String, strSubj As String, strBody As
> String,
> strFileName As String, strRSM As String)
>
> 'rpt.Filter = "RGN = " & Chr(34) & stDSM & Chr(34)
> 'DoCmd.SendObject acReport, stDocName, "Snapshot Format", stToName,
> stCCName, , stSubjLine, stBody, False
> DoCmd.OutputTo acOutputTable, "Winfull", "Microsoft Excel", strFileName
>
> Set objEmail = CreateObject("CDO.Message")
> objEmail.From = "(E-Mail Removed)"
> objEmail.To = stToName
> 'objEmail.Cc = stCCName
> objEmail.Subject = stSubjLine
> objEmail.Textbody = stBody
> objEmail.AddAttachment strFileName
> objEmail.Configuration.Fields.Item _
> ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
> objEmail.Configuration.Fields.Item _
> ("http://schemas.microsoft.com/cdo/configuration/smtpserver") =
> "xxxxxx.xxxxx.com"
> objEmail.Configuration.Fields.Item _
> ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") =
> 25
> objEmail.Configuration.Fields.Update
> objEmail.Send
>
>
> Exit Sub
>
>
> End Sub
>
>
> --
> -The Novice
> Learn Today, Teach Tomorrow
>
> Great Success is ones ability to ask for Help.



 
Reply With Quote
 
 
 
 
TheNovice
Guest
Posts: n/a
 
      2nd Apr 2008
Jeff,

Thanks for the reply. What I have is a single table that has multiple
associates that it need to go to. but only their info.

the first two queries build the working tables,

the table WinFull has all of the information that has been formatted as
requested.

So I ponder this question. is there a way that I can apply a criteria
through VBA, say;

docmd.openquery "qryWinFull" where RGN = strRSM? this would create the
table need with only that Info?!?!

as you can tell I am very new to this.

I have a good Idea as the where to put this option if only i knew how?

PLEASE any advice is always appreciated.
--
-The Novice
Learn Today, Teach Tomorrow

Great Success is ones ability to ask for Help.


"Jeff Boyce" wrote:

> I'm not clear on something.
>
> I thought you needed to send out a set of data (table or otherwise).
>
> A common approach to doing this is to create a query that returns what you
> want to export, then export that query (actually, when you do the Export,
> only the data goes.)
>
> Regards
>
> Jeff Boyce
> Microsoft Office/Access MVP
>
> "TheNovice" <(E-Mail Removed)> wrote in message
> news:B1688B08-0015-45CF-9762-(E-Mail Removed)...
> > Good morning all,
> >
> > I have a quick Question. I need to send a table out in Excel, I have the
> > code set up but I need to filter it out to equal what is on the table.
> >
> > I am recycling some old code that uses a report but the format is not what
> > we are looking for.
> >
> > Here is a sample of the code: can someone PLEASE HELP!
> >
> > Private Sub Form_Open(Cancel As Integer)
> > Dim db As Database
> > Set db = CurrentDb
> > Dim rc As Recordset
> > Dim stToName As String
> > Dim strRSM As String
> > Dim strSubj As String
> > Dim strBody As String
> > Dim strFileName As String
> > Dim rpt As TableDef
> >
> > DoCmd.SetWarnings False
> > DoCmd.OpenQuery "qryWinFull"
> > DoCmd.OpenQuery "qryWinFullTable"
> > DoCmd.SetWarnings True
> > 'DoCmd.OpenQuery "WinFull", acViewDesign
> > 'DoCmd.OpenTable Winfull, acViewNormal, acEdit
> > 'Set rpt = Table!Winfull
> > 'rpt.Visible = False
> >
> > Set rc = db.OpenRecordset("RSM Table")
> > If Not (rc.BOF Or rc.EOF) Then
> > rc.MoveFirst
> > Do Until rc.EOF
> > stToName = rc!emailid
> > strSubj = "Tomorrow's orders within 20% of Full Pallet"
> > strBody = "Please find the Enclosed Report for Tomorrow's
> > orders
> > within 20% of Full Pallet"
> > strRSM = rc![CMRSM#]
> > strFileName = "c:\commun\Within 20 Percent of Pallet for " +
> > strRSM + ".xls"
> > BuildExcelSht stToName, strSubj, strBody, strFileName, strRSM
> > 'Set rpt = Table!Winfull
> > rc.MoveNext
> > Loop
> > End If
> > DoCmd.SetWarnings False
> > DoCmd.Close acQuery, "qryWinFullTable"
> > Exit Sub
> >
> >
> > End Sub
> >
> > Sub BuildExcelSht(stToName As String, strSubj As String, strBody As
> > String,
> > strFileName As String, strRSM As String)
> >
> > 'rpt.Filter = "RGN = " & Chr(34) & stDSM & Chr(34)
> > 'DoCmd.SendObject acReport, stDocName, "Snapshot Format", stToName,
> > stCCName, , stSubjLine, stBody, False
> > DoCmd.OutputTo acOutputTable, "Winfull", "Microsoft Excel", strFileName
> >
> > Set objEmail = CreateObject("CDO.Message")
> > objEmail.From = "(E-Mail Removed)"
> > objEmail.To = stToName
> > 'objEmail.Cc = stCCName
> > objEmail.Subject = stSubjLine
> > objEmail.Textbody = stBody
> > objEmail.AddAttachment strFileName
> > objEmail.Configuration.Fields.Item _
> > ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
> > objEmail.Configuration.Fields.Item _
> > ("http://schemas.microsoft.com/cdo/configuration/smtpserver") =
> > "xxxxxx.xxxxx.com"
> > objEmail.Configuration.Fields.Item _
> > ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") =
> > 25
> > objEmail.Configuration.Fields.Update
> > objEmail.Send
> >
> >
> > Exit Sub
> >
> >
> > End Sub
> >
> >
> > --
> > -The Novice
> > Learn Today, Teach Tomorrow
> >
> > Great Success is ones ability to ask for Help.

>
>
>

 
Reply With Quote
 
APNetworking
Guest
Posts: n/a
 
      2nd Apr 2008
I'm not sure I follow exactly what you are asking, but I've done a lot of
exporting to excel and creating custom excel reports, so I'll attempt to
answer.

Here are the steps I normally take to do an excel report exported from access:

1) Create an excel template with basic formatting already in place. That way
you are inserting data into a report that already has certain column widths,
fonts, etc.

2) pull a recordset from the data table that only contains the data you want
to export. If there is filtering to be done, I do it here.

3) Copy the excel template to a new (invisible) spreadsheet and begin
writing data into the new spreadsheet.

So instead of saying
Set rc = db.OpenRecordset("RSM Table")

You could use SQL statements to filter it similar to the following:
sq = "Select * from 'RSM Table' Where AccountKey = 1234"
rc.open sq, cn

So if your sql statement is filtering properly, you can simply export all
records from the rc recordset into the excel spreadsheet without having to
filter it there.

I didn't go into too great of detail in case I misunderstood what you are
trying to do, but I'm guessing that is what you want.



"TheNovice" wrote:

> Good morning all,
>
> I have a quick Question. I need to send a table out in Excel, I have the
> code set up but I need to filter it out to equal what is on the table.
>
> I am recycling some old code that uses a report but the format is not what
> we are looking for.
>
> Here is a sample of the code: can someone PLEASE HELP!
>
> Private Sub Form_Open(Cancel As Integer)
> Dim db As Database
> Set db = CurrentDb
> Dim rc As Recordset
> Dim stToName As String
> Dim strRSM As String
> Dim strSubj As String
> Dim strBody As String
> Dim strFileName As String
> Dim rpt As TableDef
>
> DoCmd.SetWarnings False
> DoCmd.OpenQuery "qryWinFull"
> DoCmd.OpenQuery "qryWinFullTable"
> DoCmd.SetWarnings True
> 'DoCmd.OpenQuery "WinFull", acViewDesign
> 'DoCmd.OpenTable Winfull, acViewNormal, acEdit
> 'Set rpt = Table!Winfull
> 'rpt.Visible = False
>
> Set rc = db.OpenRecordset("RSM Table")
> If Not (rc.BOF Or rc.EOF) Then
> rc.MoveFirst
> Do Until rc.EOF
> stToName = rc!emailid
> strSubj = "Tomorrow's orders within 20% of Full Pallet"
> strBody = "Please find the Enclosed Report for Tomorrow's orders
> within 20% of Full Pallet"
> strRSM = rc![CMRSM#]
> strFileName = "c:\commun\Within 20 Percent of Pallet for " +
> strRSM + ".xls"
> BuildExcelSht stToName, strSubj, strBody, strFileName, strRSM
> 'Set rpt = Table!Winfull
> rc.MoveNext
> Loop
> End If
> DoCmd.SetWarnings False
> DoCmd.Close acQuery, "qryWinFullTable"
> Exit Sub
>
>
> End Sub
>
> Sub BuildExcelSht(stToName As String, strSubj As String, strBody As String,
> strFileName As String, strRSM As String)
>
> 'rpt.Filter = "RGN = " & Chr(34) & stDSM & Chr(34)
> 'DoCmd.SendObject acReport, stDocName, "Snapshot Format", stToName,
> stCCName, , stSubjLine, stBody, False
> DoCmd.OutputTo acOutputTable, "Winfull", "Microsoft Excel", strFileName
>
> Set objEmail = CreateObject("CDO.Message")
> objEmail.From = "(E-Mail Removed)"
> objEmail.To = stToName
> 'objEmail.Cc = stCCName
> objEmail.Subject = stSubjLine
> objEmail.Textbody = stBody
> objEmail.AddAttachment strFileName
> objEmail.Configuration.Fields.Item _
> ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
> objEmail.Configuration.Fields.Item _
> ("http://schemas.microsoft.com/cdo/configuration/smtpserver") =
> "xxxxxx.xxxxx.com"
> objEmail.Configuration.Fields.Item _
> ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
> objEmail.Configuration.Fields.Update
> objEmail.Send
>
>
> Exit Sub
>
>
> End Sub
>
>
> --
> -The Novice
> Learn Today, Teach Tomorrow
>
> Great Success is ones ability to ask for Help.

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Automatically send e-mails / send mailwithout press outlook send b =?Utf-8?B?TWFyY28=?= Microsoft Access Forms 0 28th Mar 2007 01:17 AM
Toolbar option available for TABLE>INSERT>TABLE to enclose text into a table? StargateFan Microsoft Word New Users 5 30th Jan 2005 12:10 AM
MAPI and (texteditorapp)/File/Send-> (err)Send Mail failed to send =?Utf-8?B?c25vd21vc3M=?= Windows XP Help 3 13th Oct 2004 12:47 AM
Help updating table from linked table(linked table is a csv) Thierry Microsoft Access Queries 2 29th Jun 2004 02:21 PM
using Send.Send() or Send.SendWait() to cause audio mute to happen Andy Purcell Microsoft C# .NET 0 28th Jun 2004 09:02 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:15 PM.