Is there a way to pass a value to a report via VBA so the value can then be displayed in the report as a concantenation with a string?
I have a report that displays all pricings that have occured in one day. I would like to display the pricing date in the report header. However, if there were no pricings for the date being viewed, I return no records so I can't pull the pricing date from my query results and thus want to set it programatically .
The form to display the pricing reports has two buttons. One for 'display today's pricings' and another for 'display pricings for x date'. Both buttons open the same report and the OpenReport command includes Where criteria to show only the desired date's data. With the exception of the db admin, all users will only ever look at pricings for the current day so the 'display today's pricings' button has: - strCriteria = "PricingDate = Date()"
-
DoCmd.OpenReport "DailyPricings", acViewPreview, , strCriteria
The db admin will sometimes need to view past pricing reports so the 'display pricings for x date' button has: - strReportDate = InputBox("Please enter the desired report date", "Report Date", Date-1)
-
strCriteria = "PricingDate = #" & strReportDate & "#"
-
DoCmd.OpenReport "DailyPricings", acViewPreview, , strCriteria
I could have all users use the inputbox and set the inputbox default to Date then move all the code to the Report_Open event, but that means the majority of users will always have to click an extra button in the process of viewing the day's report.
In the Report_Open event, I want to do something like: - Dim strHeader as String
-
strHeader = "2008 Pricings for " & datReportDate
-
Me.lblHeader.Caption = strHeader
So is there a way I can pass the value for datReportDate to the Report_Open event as either the current day's date if user clicked 'view today's date' or as the user-entered date if user clicked 'view pricings for x date'? I apologize for the long post. The answer seems like it should be simple but, at this point, I'm so backwards in cleaning up this database I inherited that I can't see straight.
4 13361
You should set the caption property of the label while form is in design mode, then open in preview. For example: - Dim strHeader as String
-
strHeader = "2008 Pricings for " & datReportDate
-
DoCmd.OpenReport "DailyPricings", acViewDesign
-
With Reports!DailyPricings
-
.lblHeader.Caption = strHeader
-
End With
-
DoCmd.Save acReport, "DailyPricings"
-
DoCmd.OpenReport "DailyPricings", acViewPreview, , strCriteria
-
Hi. You can also use the OpenArgs property to pass a string value to the report which can be retrieved using event code in the On Activate event of the form:
in the form code that opens the report: - DoCmd.OpenReport "Reportname", acPreview,,,,me.yourcontrolvalue
in the report's On Activate property - Private Sub Report_Activate()
-
If Not IsNull(me.openargs) then
-
Me.YourHeaderCtrl = Me.OpenArgs
-
end if
-
End Sub
You could also use the On Open event, but unfortunately you would not be able to set a value for a report control that way as the control's value is not available until after the report is opened.
If you look up the Help for OpenArgs you will see examples of record matching.
-Stewart
Thank you both so much for your help! I was able to implement jpatchak's suggestion (although I did need to close the form between saving and opening in Preview view in order for the strCriteria to take effect).
I will now work my way through the openargs suggestion as I need all the opportunities for learning Access I can get. Thank you again!
Hey I have Done exactly what you guys have done using the With statement in Post #2. When I do that I get an error saying: This Property is not available in design view. So I changed the view to Preview and I get the error saying: You can't reference a property or method for a control unless the control has the focus.
help please.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Lukelrc |
last post by:
Hi all,
I have an asp page with a delete button which has an OnClick Ok/Cancel
msgbox event. My problem is that in order to run the Onclick event
i've chaged the buttons type from "Submit" to "Button" - and now the
buttons value (which i need in the next page) is not passed in the
URL.
This is what i have tried to do:
|
by: Mike |
last post by:
I have to pass a date from a form to a report query. I have written a
query that works fine when I execute from SQL view, But I dont know
how to pass a value from the form to this query.
SELECT Production.Production
FROM Production
WHERE (((Production.Date)=Forms!ReportForm!reportDate) And
((Production.ShiftName)="Shift1"));
|
by: rcmail14872 |
last post by:
I used the upsize wizard to change my Access 2002 database to a SQL
Server ADP project. I had a form where the user entered a value into a
text box and when a command button on the form was clicked a Report was
opened. The reports record source is a query. The query uses the
value from the form text box to restrict the query.
Table name = EggsTable
one of the columns in the table is named: EggColor
Form name = EggColorForm
Form text...
|
by: SalimShahzad |
last post by:
dear guruys,
can any one put highlights...
if i have 2 queries, how one can pass parameter as variable to
report/query...
i had posted earlier also but no reply...
say v have string value city names...so i wanted to print all cities
|
by: Yama |
last post by:
Hi,
Simple question:
Is there a way to a value from client-side to server-side upon a click?
function _getReport(ReportName) { alert(ReportName); }
<asp:datalist id="dlReports" runat="server">
<itemtemplate>
| |
by: sangram |
last post by:
Passing value from parent to child window created by Pop up
|
by: Shailja |
last post by:
Hi,
I am using VB as front-end. I want to pass the value of variable to Crystal Report. Variable contains ID of the record. I want to display record of that ID in crystal report.
I dont know how to do that? Kindly let me know if u know the answer
|
by: idsanjeev |
last post by:
SIR I AM PASSING VALUE FROM ONE FORM TO ANOTHER FORM THROUGH COOKIES BUT IS CAN ONLY TRANSFER LAST VALUE
HOW CAN PASS VALUE AFTER CLICKIN ON LINK
I AM USING THE CODE IS
FOR LINK
<td><a href=voicereply.asp?opt1=<%=R("top_id")%>>Reply</a></td>
FOR STORING IN COOKIES
response.cookies("vtopid")=R("top_id")
TO PASS ON NEXT PAGE AND WANT TO INSERT TOPID IN TO TABLE
FOR DISLAY
|
by: sva0008 |
last post by:
hi , I am using.
<input type=button class=tbox value="Populate SA" style="width: 90%" onClick="window.location='../SA/Sample.asp?ToDo=FromFeed&ContactName=<%=FirstName%>&Address=<%=Address%>&City=<%=City%>&State=<%=state%>&ZipCode=<%=Zip%>&Phone=<%=ContactPhone%>&Notes=<%=Comments%><%=resolution%>&ordDate=<%=Date%>';" >
for passing value from one page to another but i want to take care of single quote . eg if the first name contains...
|
by: perhapscwk |
last post by:
how to passing value from popup to the parent window as a variable
which I can access and process the variable(string) in parent window?
such as from popup page, we have var_from_popup="abc", after the popup
closed, then from parent window, we can use alert(var_from_popup) and
it will show us the "abc"?
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |