Hi Ken,
I have made qryA. I'd like to compare qryTmp in my code
to qryA and if there is a discrepancy, replace qryA (i.e.
save qryTemp as qryA)
Is this possible?
Once again Thanks for all your help! There are so many
keywords I don't even know where to start looking!
Hafeez Esmail
-----Original Message-----
You want to save the results of the query that is being
displayed in the
report? If yes, the DoCmd.Save command will not do this
for you. That
command is used to save changes made to the design view
of an object. It
won't save the displayed data.
You need to use a MakeTable query that is based on the
report's query to put
the data into a table so that you can save it.
Alternatively, you can "save"
the report by using the OutputTo command to save the
report in an ".rtf"
format. You wouldn't need to open the report first; just
be sure that the
report's query is set up and then use this command:
DoCmd.OutputTo acReport, "ReportName",
acFormatRTF,
"C:\MyFolder\ReportName.rtf"
--
Ken Snell
<MS ACCESS MVP>
Hi Ken,
Thanks for the confirmation
I seem to be having a problem with this code now
DoCmd.Save acReport, "RptPredef" & strLastName
I want to save the resulting search (i don't care which
format it's in) but I can't seem to be able to do it.
Thanks in advance
Hafeez Esmail
-----Original Message-----
Yes, you can open more than one recordset in a code
snippet.
You don't need the Where word in the line of code.
Change
it to this:
rstrec!Last_Name = strLastName
You correctly identified that you needed to set a
reference to DAO library.
--
Ken Snell
<MS ACCESS MVP>
I've set the references to DA 3.6 (I wasn't in Design
Mode) but the error I'm having now is at my Where
condition
(Where rstrec!Last_Name = strLastName)
Public Function MakeRpts()
Dim rstrec As DAO.Recordset
Dim rstname As DAO.Recordset
Dim dbs As DAO.Database
Dim strLastName As String
Set dbs = CurrentDb()
Set rstname = dbs.OpenRecordset("TblFHStaffList")
Set rstrec = dbs.OpenRecordset("QryPredef120")
If rstname.BOF = False And rstname.EOF = False Then
rstname.MoveFirst
Do While rstname.EOF = False
Set strLastName = rstname!Last_Name
If rstrec.BOF = False And rstrec.EOF = False
Then
rstrec.MoveFirst
Do While rstrec.EOF = False
Where rstrec!Last_Name = strLastName
rstrec.MoveNext
Loop
DoCmd.Save acReport, "RptPredef" &
strLastName
End If
rst.MoveNext
Loop
rstname.Close
Set rstname = Nothing
rstrec.Close
Set rstrec = Nothing
dbs.Close
Set dbs = Nothing
End Function
-----Original Message-----
Error in my first example for case one...sorry:
Dim rst As DAO.Recordset
Dim dbs As DAO.Database
Dim strLastName As String
strLastName = InputBox("Enter the person's last
name:")
Set dbs = CurrentDb()
Set rst = dbs.OpenRecordset
("TableNameWithPerson'sLastName")
If rst.BOF = False And rst.EOF = False Then
rst.MoveFirst
Do While rst.EOF = False
If rst!LastNameFieldName = strLastName Then
DoCmd.SendObject ' add the
appropriate
arguments to this line
End If
rst.MoveNext
Loop
End If
rst.Close
Set rst = Nothing
dbs.Close
Set dbs = Nothing
--
Ken Snell
<MS ACCESS MVP>
"Ken Snell" <
[email protected]>
wrote
in
message
RE: case one, you cannot use a macro. You will
need
to
use VBA code to
open
a recordset based on the table and then to loop
through
the recordset. I'm
not sure what you mean by the query is using a
parameter based on the
person's last name? If you have a basic query (no
parameter), you don't
need
to run it in order to email it; just email the
query
(SendObject) and it
will run and export its results. Something like
this:
Dim rst As DAO.Recordset
Dim dbs As DAO.Database
Dim strLastName As String
strLastName = InputBox("Enter the person's last
name:")
Set dbs = CurrentDb()
Set rst = dbs.OpenRecordset
("TableNameWithPerson'sLastName")
If rst.BOF = False And rst.EOF = False Then
rst.MoveFirst
Do While rst.EOF = False
If rst!LastNameFieldName = strLastName
Then
DoCmd.SendObject ' add the
appropriate
arguments to this
line
End If
rst.MoveNext
Loop
rst.Close
Set rst = Nothing
dbs.Close
Set dbs = Nothing
If what you desire is to use each person's last
name
as
the parameter for
the query and to email each "filtered" query to
just
that one person, I
don't have a ready answer for you at the moment.
I
would anticipate that
you'd need to use the QueryDefs collection of the
Database object in order
to get the query and evaluate the parameter using
each
last name from the
table, and then likely you'd need to have that
query
export its results
into
a temporary table, and then email that table;
then
clear the table and go
to
the next record in the table until all done. I've
not
worked with this
before, so I'm not sure of all the nuances and
will
need a bit of time to
try a few things before I can post a possible
solution
for you.
I'm tied up on some personal business at the
moment,
so
it will be a few
days before I can post a possible idea.
--
Ken Snell
<MS ACCESS MVP>
[email protected]...
Hi Ken,
I want to do something similar to this and have
thought of
two ways to carry it (neither of which I know
how
to
do).
Case one (ideal solution):
I have a query based on a paramter (i.e.
Last_Name).
The
following tasks is what I want it to do
automatically:
1 Run query
2 Enter employee's last name based on a table
3 Email query to employee
*loop through all names in table*
Case two (easier??):
I have 50 different queries that need to be
executed
and
emailed to each employee respectively. Is
there
an
easy
way to do this?
Hafeez Esmail
-----Original Message-----
Try this:
Public Function sendmail()
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim strSubject As String
Dim strEmailmessage As String
Dim strEmailadress As String
strEmailadress = ""
strSubject = Forms!form1!txtSubject
strEmailmessage = Forms!form1!txtMessage
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("mail")
rst.MoveFirst
Do Until rst.EOF
strEmailadress = strEmailadress & rst! [email2]
& ";"
rst.MoveNext
Loop
DoCmd.SendObject , , acFormatHTML,
strEmailadress, , ,
strSubject,
strEmailmessage, False, False
rst.Close
Set rst = Nothing
dbs.Close
Set dbs = Nothing
--
Ken Snell
<MS ACCESS MVP>
message
Hey, in the code below, access uses one e-
mailadress at
the time. What is
the code to send all the adresses in one
time
to
the
Emailadres ? (now, if
i
have 100 adresses, so I need to create the
text
100
times and press the
"send button 100 time)
Any help is welcome.
this is my code
Public Function sendmail()
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim strSubject As String
Dim strEmailmessage As String
Dim strEmailadress As String
strSubject = Forms!form1!txtSubject
strEmailmessage = Forms!form1!txtMessage
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("mail")
rst.MoveFirst
Do Until rst.EOF
strEmailadress = rst![email2]
DoCmd.SendObject , , acFormatHTML,
strEmailadress, , ,
strSubject,
strEmailmessage, False, False
rst.MoveNext
Loop
rst.Close
Set rst = Nothing
dbs.Close
Set dbs = Nothing
End Function
.
.
.
.
.