473,797 Members | 3,183 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Event Code

I have a form called "EmpRpt". It has three fields. First field is
"chrUserID, " this is a combo box with a row source from another table. The
Second Field is "BeginDate. " The Third field is "EndDate."

I then have a command button. I want to put a code in this buttons on click
event. The code should open up a report called "EmpRpt."

The report will have the three fields just like the form. I want those three
fields to appear with the data the user entered in the form. I would also
like this report to open in print preview.

Can someone please help me with a code? Thank you!

--
Message posted via AccessMonster.c om
http://www.accessmonster.com/Uwe/For...ccess/200708/1

Aug 9 '07 #1
11 2080
See:
Print the record in the form
at:
http://allenbrowne.com/casu-15.html

Note that your table must have a primary key so you can be certain the
report has the same record.

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"ladybug via AccessMonster.c om" <u21071@uwewrot e in message
news:767016588c ee4@uwe...
>I have a form called "EmpRpt". It has three fields. First field is
"chrUserID, " this is a combo box with a row source from another table.
The
Second Field is "BeginDate. " The Third field is "EndDate."

I then have a command button. I want to put a code in this buttons on
click
event. The code should open up a report called "EmpRpt."

The report will have the three fields just like the form. I want those
three
fields to appear with the data the user entered in the form. I would also
like this report to open in print preview.

Can someone please help me with a code? Thank you!
Aug 9 '07 #2
ladybug via AccessMonster.c om wrote:
I have a form called "EmpRpt". It has three fields. First field is
"chrUserID, " this is a combo box with a row source from another table. The
Second Field is "BeginDate. " The Third field is "EndDate."

I then have a command button. I want to put a code in this buttons on click
event. The code should open up a report called "EmpRpt."

The report will have the three fields just like the form. I want those three
fields to appear with the data the user entered in the form. I would also
like this report to open in print preview.

Can someone please help me with a code? Thank you!
You could create a query called EmpRpt. Add the 2 tables (since the
combo is linked) you use and drag down the fields you want from the 2
tables. Save the query.

Go to Reports, click New, and use the ReportWizard. Select the query
EmpRpt. Follow the steps to create the report. Save it as EmpRpt.

Now in your command button you open the property sheet to the event tab
and select the OnCLick event. You could enter
Docmd.OpenRepor t "EmpRpt",acView Preview

You can filter it as well. Lets say you have a field called EmpID and
it is numeric. You could enter
Docmd.OpenRepor t "EmpRpt",acView Preview,,"EmpID = " & Me.chrUserID
and this will display the report for the current empid.

Now it's possible you might open a report where all of the data has not
been saved. If this were a new record, the report might even say no
data exists! So sometimes you might want to save the record first
before displaying a report. Your code might look like this
If Me.Dirty then Me.Dirty = False
Docmd.OpenRepor t...
or
If Me.Dirty then DoCmd.RunComman d acCmdSaveRecord
Docmd.OpenRepor t...
Aug 9 '07 #3
I did what you gave me and I rcvd an error that I have entered an expression
that has an invalid reference to the property dirty. I took out that section
of the code and it opens the report, but no data is captured. Here is the
code I have:

Private Sub Command6_Click( )
Dim strWhere As String

If Me.NewRecord Then 'Check there is a record to print
MsgBox "Select a record to print"
Else
strWhere = "[chrUserId] = " & Me.[chrUserID]
DoCmd.OpenRepor t "EmpRpt", acViewPreview, , strWhere
End If
End Sub
Allen Browne wrote:
>See:
Print the record in the form
at:
http://allenbrowne.com/casu-15.html

Note that your table must have a primary key so you can be certain the
report has the same record.
>>I have a form called "EmpRpt". It has three fields. First field is
"chrUserID, " this is a combo box with a row source from another table.
[quoted text clipped - 11 lines]
>>
Can someone please help me with a code? Thank you!
--
Message posted via AccessMonster.c om
http://www.accessmonster.com/Uwe/For...ccess/200708/1

Aug 9 '07 #4
What two tables? There is no table for the dates they are just text fields.
Salad wrote:
>I have a form called "EmpRpt". It has three fields. First field is
"chrUserID, " this is a combo box with a row source from another table. The
[quoted text clipped - 8 lines]
>>
Can someone please help me with a code? Thank you!

You could create a query called EmpRpt. Add the 2 tables (since the
combo is linked) you use and drag down the fields you want from the 2
tables. Save the query.

Go to Reports, click New, and use the ReportWizard. Select the query
EmpRpt. Follow the steps to create the report. Save it as EmpRpt.

Now in your command button you open the property sheet to the event tab
and select the OnCLick event. You could enter
Docmd.OpenRepor t "EmpRpt",acView Preview

You can filter it as well. Lets say you have a field called EmpID and
it is numeric. You could enter
Docmd.OpenRepor t "EmpRpt",acView Preview,,"EmpID = " & Me.chrUserID
and this will display the report for the current empid.

Now it's possible you might open a report where all of the data has not
been saved. If this were a new record, the report might even say no
data exists! So sometimes you might want to save the record first
before displaying a report. Your code might look like this
If Me.Dirty then Me.Dirty = False
Docmd.OpenRepor t...
or
If Me.Dirty then DoCmd.RunComman d acCmdSaveRecord
Docmd.OpenRepor t...
--
Message posted via AccessMonster.c om
http://www.accessmonster.com/Uwe/For...ccess/200708/1

Aug 9 '07 #5
If the form does not have a Dirty property, then it is an unbound form.

If it is an unbound form, then there is no current record to print.

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"ladybug via AccessMonster.c om" <u21071@uwewrot e in message
news:7670a6cdcc 48f@uwe...
>I did what you gave me and I rcvd an error that I have entered an
expression
that has an invalid reference to the property dirty. I took out that
section
of the code and it opens the report, but no data is captured. Here is the
code I have:

Private Sub Command6_Click( )
Dim strWhere As String

If Me.NewRecord Then 'Check there is a record to print
MsgBox "Select a record to print"
Else
strWhere = "[chrUserId] = " & Me.[chrUserID]
DoCmd.OpenRepor t "EmpRpt", acViewPreview, , strWhere
End If
End Sub
Allen Browne wrote:
>>See:
Print the record in the form
at:
http://allenbrowne.com/casu-15.html

Note that your table must have a primary key so you can be certain the
report has the same record.
>>>I have a form called "EmpRpt". It has three fields. First field is
"chrUserID, " this is a combo box with a row source from another table.
[quoted text clipped - 11 lines]
>>>
Can someone please help me with a code? Thank you!
Aug 9 '07 #6
ladybug via AccessMonster.c om wrote:
What two tables? There is no table for the dates they are just text fields.
You stated "First field is "chrUserID, " this is a combo box with a row
source from another table..."

So I figured 2 tables were in play. Sometimes combos can have multiple
columns and I figured the data in the combo might be used as well as the
other fields.
>
Salad wrote:
>>>I have a form called "EmpRpt". It has three fields. First field is
"chrUserID ," this is a combo box with a row source from another table. The

[quoted text clipped - 8 lines]
>>>Can someone please help me with a code? Thank you!

You could create a query called EmpRpt. Add the 2 tables (since the
combo is linked) you use and drag down the fields you want from the 2
tables. Save the query.

Go to Reports, click New, and use the ReportWizard. Select the query
EmpRpt. Follow the steps to create the report. Save it as EmpRpt.

Now in your command button you open the property sheet to the event tab
and select the OnCLick event. You could enter
Docmd.OpenRepor t "EmpRpt",acView Preview

You can filter it as well. Lets say you have a field called EmpID and
it is numeric. You could enter
Docmd.OpenRepor t "EmpRpt",acView Preview,,"EmpID = " & Me.chrUserID
and this will display the report for the current empid.

Now it's possible you might open a report where all of the data has not
been saved. If this were a new record, the report might even say no
data exists! So sometimes you might want to save the record first
before displaying a report. Your code might look like this
If Me.Dirty then Me.Dirty = False
Docmd.OpenRepor t...
or
If Me.Dirty then DoCmd.RunComman d acCmdSaveRecord
Docmd.OpenRepor t...

Aug 9 '07 #7
So why do I get the error for the Dirty property?

Allen Browne wrote:
>If the form does not have a Dirty property, then it is an unbound form.

If it is an unbound form, then there is no current record to print.
>>I did what you gave me and I rcvd an error that I have entered an
expression
[quoted text clipped - 27 lines]
>>>>
Can someone please help me with a code? Thank you!
--
Message posted via AccessMonster.c om
http://www.accessmonster.com/Uwe/For...ccess/200708/1

Aug 9 '07 #8
The dates do not come from a table. This is just a form which sets the
criteria that will be used when opening the report.

Salad wrote:
>What two tables? There is no table for the dates they are just text fields.

You stated "First field is "chrUserID, " this is a combo box with a row
source from another table..."

So I figured 2 tables were in play. Sometimes combos can have multiple
columns and I figured the data in the combo might be used as well as the
other fields.
>>>>I have a form called "EmpRpt". It has three fields. First field is
"chrUserID, " this is a combo box with a row source from another table. The
[quoted text clipped - 28 lines]
>>> If Me.Dirty then DoCmd.RunComman d acCmdSaveRecord
Docmd.OpenRepor t...
--
Message posted via AccessMonster.c om
http://www.accessmonster.com/Uwe/For...ccess/200708/1

Aug 9 '07 #9
If the error is as you said - invalid reference to the property dirty - it
is because your form is unbound.

(If the error said you can't set the property, it's because the record
cannot be saved.)

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"ladybug via AccessMonster.c om" <u21071@uwewrot e in message
news:7671418c98 553@uwe...
So why do I get the error for the Dirty property?

Allen Browne wrote:
>>If the form does not have a Dirty property, then it is an unbound form.

If it is an unbound form, then there is no current record to print.
>>>I did what you gave me and I rcvd an error that I have entered an
expression
[quoted text clipped - 27 lines]
>>>>>
Can someone please help me with a code? Thank you!
Aug 9 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

18
2889
by: Christopher W. Douglas | last post by:
I am writing a VB.NET application in Visual Studio 2003. I have written a method that handles several events, such as closing a form and changing the visible status of a form. I have some code that applies to all these events, but I need to have specific code execute when the form closes. The properties for this method are sender (the originator) and e (event arguments). I know how to get typeof (sender) to determine what form or...
6
1877
by: vbMark | last post by:
If I have a control, for example a CheckedListBox, how do I add and event to code, for example that a box has been checked by the user? Thanks
3
3645
by: R Millman | last post by:
under ASP.NET, single stepping in debug mode appears not to stop within event procedures. i.e. 1) Create web page with submit button and event procedure for the click event in the code behind page, 2) Breakpoint in the Page_Load, 3) debug the web page and click the submit button, 4) "step into" under debug several times, 5) The debugger does not stop at any of the statements in the click event handler. A breakpoint is needed in each...
7
390
by: Charles Law | last post by:
I may have asked this before, but what is the purpose of both these functions? Is there a time when one should be called over the other? Does one supersede the other, or do they both have their time and place? TIA Charles
13
3519
by: Charles Law | last post by:
Mr "yEaH rIgHt" posted the following link about a week ago in answer to my question about removing event handlers. > http://www.vbinfozine.com/t_bindevt.shtml Following on from that post, the following issues still exist. The article shows how to find methods on a receiver that match the pattern OnXXXX given the sender. It loops through the sender events and tries to get methods from the receiver that match the pattern. For each one...
41
4331
by: JohnR | last post by:
In it's simplest form, assume that I have created a usercontrol, WSToolBarButton that contains a button. I would like to eventually create copies of WSToolBarButton dynamically at run time based on some initialization information obtained elsewhere. Basically, I'm going to create my own dynamic toolbar where the toolbarbuttons can change. I'm not using the VB toolbar because of limitations in changing things like backcolor (I can't get...
9
2472
by: jeff | last post by:
New VB user...developer... Situation...simplified... - I want to wrap a pre and post event around a system generated where the pre-event will always execute before the system event and the post event will always execuate after the system is completed... - I want to wrap this functionality in a framework, so I could possibly have 3 or 4 levels of inherited objects that need to have these pre / post events executed before and after the...
3
5544
by: geskerrett | last post by:
We have been asked to develop and application for a client that is a 'notification" system. We would like to use python, but are struggling to find the right starting point. Any suggestions, tips or sample code would be appreciated. Application outline; Machine A is running a "listener" application that is connected to a another device via the serial post and waits for events. We have not problem working with the serial port, or...
19
4759
by: Daniela Roman | last post by:
Hello, I try to fire an event under a button click event and maybe anybody can give a clue please. I have let's say a WEB grid with PageIndexChanged event: private void DataGrid1_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
4
237
by: tshad | last post by:
I am just getting started with events and had a couple of questions on why they do what they do. If you have a textbox and you want to handle an event you can just do: this.TextBox2.TextChanged += new EventHandler(TextBox2_TextChanged); and then have the function. void TextBox2_TextChanged(object sender, EventArgs e)
0
9685
marktang
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...
0
10469
Oralloy
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10246
jinu1996
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...
0
10023
tracyyun
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...
0
9066
agi2029
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...
0
6803
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5459
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...
1
4135
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2934
bsmnconsultancy
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.