I have a form with a macro that has the action "SendObject" that sends a report by email. In the report itself I have macro that displays a messagebox if no records were found.
What I want o achieve is to halt the "SendObject" macro if no records were found and stop loading Outlook, instead display the parameter box for the report once more to let the user input a valid string after the messagebox that warns for No Records
-Sohail
7 3381 @lupis
Let the User enter the Criteria for the Report on a Text Box on a Form, then check for the existence of any Records prior to opening the Report itself. Loop until Records matching the Criteria are met, or until the User says No. - Dim varLastName As Variant
-
Dim intNumOfRecs As Integer
-
Dim intResponse As Integer
-
-
varLastName = Me![txtLastName]
-
-
If IsNull(varLastName) Then
-
MsgBox "You must enter a Last Name", vbExclamation, "No Name Entered"
-
Me![txtLastName].SetFocus
-
Exit Sub
-
End If
-
-
Do
-
intNumOfRecs = DCount("*", "Employees", "[LastName] = '" & varLastName & "'")
-
-
If intNumOfRecs = 0 Then
-
intResponse = MsgBox("No Records exists for a Last name of [" & varLastName & "], try again?", _
-
vbQuestion + vbYesNo + vbDefaultButton1, "Parameter Prompt")
-
If intResponse = vbYes Then Me![txtLastName].SetFocus: Exit Sub
-
Else 'Record(s) exist, Run Macro or execute code here
-
'Now OK, Run Macro or initiate SendObject
-
End If
-
Loop Until intNumOfRecs > 0 Or intResponse = vbNo
P.S. - Instead of a Parameter Prompt, the Criteria for the Report's Row Source would point to a Form Field as in: - Forms![frmYaDaYaDa]![txtLastName]
Great, I am really thanksfull for your advice. I have just one more question.
Here is the code for the "SendObject": - 'Record(s) exist, Run Macro or execute code here
-
-
-
On Error GoTo cmdSendReport_Click_Err
-
-
DoCmd.OpenReport "PurchaseByPerson", acViewReport, "", "", acNormal
-
-
DoCmd.SendObject acReport, "PurchaseByPerson", "PDFFormat(*.pdf)", "", "", "", "Dina poster", "Härär dem poster du har köpt av CBC", True, ""
-
When the Send Object fires, and the Outlook form pops up, the minimize property is disabled, so I cant view the report behind, I can maximize the email form or cancel the email form, which then fires a messagebox telling "The Send Object action was cancelled" This denies the usser to see the generated report prior to sending it. Is there any way to have focus on the report first instead of the mailform, or to have the mailform minimize property set to true?
-Thanks
@lupis
This is a little tricky, but you can try the following: - Dim varLastName As Variant
-
Dim intNumOfRecs As Integer
-
Dim intResponse As Integer
-
-
varLastName = Me![txtLastName]
-
-
If IsNull(varLastName) Then
-
MsgBox "You must enter a Last Name", vbExclamation, "No Name Entered"
-
Me![txtLastName].SetFocus
-
Exit Sub
-
End If
-
-
Do
-
intNumOfRecs = DCount("*", "Employees", "[LastName] = '" & varLastName & "'")
-
-
If intNumOfRecs = 0 Then
-
intResponse = MsgBox("No Records exists for a Last name of [" & varLastName & "], try again?", _
-
vbQuestion + vbYesNo + vbDefaultButton1, "Parameter Prompt")
-
If intResponse = vbYes Then Me![txtLastName].SetFocus: Exit Sub
-
Else 'Record(s) exist, Run Macro or execute code here
-
DoCmd.OpenReport "rptTest", acViewPreview
-
intResponse = MsgBox("EMail Report?", vbQuestion + vbYesNo, "E-Mail Confirmation")
-
If intResponse = vbYes Then
-
DoCmd.Close acReport, "PurchaseByPerson"
-
DoCmd.SendObject acReport, "PurchaseByPerson", "PDFFormat(*.pdf)", "", "", "", "Dina poster", _
-
"Härär dem poster du har köpt av CBC", True, ""
-
Else
-
DoCmd.Close acReport, "rptTest"
-
Exit Sub
-
End If
-
End If
-
Loop Until intNumOfRecs > 0 Or intResponse = vbNo
I tried it out. This is what happens: - On button click
- Email confirmation messagebox appears
- Report is only vissible beyond the form, not accessable because Email confirmation has focus
- On yes, the report dissapears and Outlook form appears
- On No, report closes
If the report had focus in front of the form,then it would work, becuase I could move the messagebox around and the confirm to email report or not.
This is the code I am firing for the button event: - '------------------------------------------------------------
-
' cmdSendReport_Click
-
'
-
'------------------------------------------------------------
-
Private Sub cmdSendReport_Click()
-
Dim varName As String
-
Dim intNumOfRecs As Integer
-
Dim intResponse As Integer
-
-
varName = Me![txtName]
-
-
If IsNull(varName) Then
-
MsgBox "You must enter a Name", vbExclamation, "No Name Entered"
-
Me![txtName].SetFocus
-
Exit Sub
-
End If
-
-
Do
-
intNumOfRecs = DCount("*", "qSalesQueryLastName", "[Name] = '" & varName & "'")
-
-
If intNumOfRecs = 0 Then
-
intResponse = MsgBox("No Records exists for a Name of [" & varName & "], try again?", _
-
vbQuestion + vbYesNo + vbDefaultButton1, "Parameter Prompt")
-
If intResponse = vbYes Then Me![txtName].SetFocus: Exit Sub
-
Else
-
'Record(s) exist, Run Macro or execute code here
-
-
-
On Error GoTo cmdSendReport_Click_Err
-
-
-
-
DoCmd.OpenReport "PurchaseByPerson", acViewPreview
-
intResponse = MsgBox("EMail Report?", vbQuestion + vbYesNo, "E-Mail Confirmation")
-
If intResponse = vbYes Then
-
DoCmd.Close acReport, "PurchaseByPerson"
-
DoCmd.SendObject acReport, "PurchaseByPerson", "PDFFormat(*.pdf)", "", "", "", "Dina poster", _
-
"Härär dem poster du har köpt av CBC", True, ""
-
Else
-
DoCmd.Close acReport, "PurchaseByPerson"
-
Exit Sub
-
End If
-
End If
-
-
-
cmdSendReport_Click_Exit:
-
Exit Sub
-
-
cmdSendReport_Click_Err:
-
MsgBox Error$
-
Resume cmdSendReport_Click_Exit
-
-
-
-
-
Loop Until intNumOfRecs > 0 Or intResponse = vbNo
-
-
End Sub
-
-
-
Also when supplying a empty string, I am getting run time error 94 "Invalid use of null"
The debugger stops at: @lupis
Why does the Report need to be accessible and simply not visible?
Sorry, I mean actually vissible, its is partially vissible, but as long as the SendObject has focus with the email form and the report is behind the form, I cant see the report completly or its result
Sign in to post your reply or Sign up for a free account.
Similar topics
by: mike420 |
last post by:
I think everyone who used Python will agree that its syntax is
the best thing going for it. It is very readable and easy
for everyone to learn. But, Python does not a have very good
macro...
|
by: Dr. Know |
last post by:
I am working on an ASP page that writes to several databases, ranging
from MDBs to x-base.
One of the tasks involves using an existing highest value from the DB
and incrementing it before...
|
by: Tony Williams |
last post by:
I have two tables 1.tblmonth which holds two fields txtmonth and txtqtrlabel
and 2. tblmain which holds a number of fields but in particular a field
called txtqtrlabel2. The two tables are linked...
|
by: Dlady2004 |
last post by:
I am trying to create a macro that opens a form and displays a message box
and records if the condition holds true if no records match I want it to
go to the next criteria in another form here is...
|
by: tmountjr |
last post by:
I've got a user who's trying to export a text file with unicode
formatting. When he exports it as straight ascii, some of the foreign
characters (mostly just accent marks and the like - no...
|
by: Yan |
last post by:
A lot of times when reading open software, i come across macros that are
defined as follows:
#define CALL_FUNCS(x) \
do { \
func1(x); \
func2(x); \
func3(x); \
} while (0);
|
by: Efim |
last post by:
Hi all,
Due to performance issue, I want to pevent execution of ToString() function
in the code like the following:
if(reporting_level & DEBUG_LEVEL)
log(reporting_level,string.Format("Event of...
|
by: Fred Nelson |
last post by:
Hi:
I'm trying to write a routine that will permit my VB.NET program to
pause execution for five minutes and try a task again if there is a
failure. After a set number of tries it should return...
|
by: greg |
last post by:
Hi,
Can anyone help me with the following issue:
How can I pause the execution of a program until a given file is
created (by another process) in a specified directory?
Any ideas would be...
|
by: thesti |
last post by:
hello,
i have some jbuttons in my frame.
and i have a recursive method, which will check a certain condition and if satisfied, will move one of the jbuttons location to somewhere else in the...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
| |