Newbie here! Some criteria to see last Record on my report? (1 Viewer)

soumelaki

New member
Local time
Today, 09:35
Joined
Apr 9, 2024
Messages
13
Hello
Im a new access programmer. All i knew is from Youtube and many posts here.

I have a database. I created a table a form and a report.
I created a button in my form to print the report i created.
But when i press the button the report that shows me is all the records.

Is there any criteria to report me only the last record i created ?
Thank you!!
 

June7

AWF VIP
Local time
Yesterday, 22:35
Joined
Mar 9, 2014
Messages
5,488
Apply filter to report. There are several ways to accomplish this. If the form is open and that record has focus, code can reference the ID value. The record must first be committed to table. In VBA it would look like:

If Me.Dirty Then Me.Dirty = False
DoCmd.OpenReport "report name here", acViewPreview, , "ID=" & Me.ID

This assumes you have an autonumber field named ID. Otherwise, modify code as appropriate.
 
Last edited:

soumelaki

New member
Local time
Today, 09:35
Joined
Apr 9, 2024
Messages
13
Apply filter to report. There are several ways to accomplish this. If the form is open and that record has focus, code can reference the ID value. In VBA it would look like:

DoCmd.OpenReport "report name here", acViewPreview, , "ID=" & Me.ID

This assumes you have an autonumber field named ID. Otherwise, modify code as appropriate.

can you please help me where is the VBA ? where can copy this (DoCmd.OpenReport "report name here", acViewPreview, , "ID=" & Me.ID) ?
 

June7

AWF VIP
Local time
Yesterday, 22:35
Joined
Mar 9, 2014
Messages
5,488
I edited my previous post - review again.

How are you currently opening report? You said you have a button on form to open report. What is your code?
 

soumelaki

New member
Local time
Today, 09:35
Joined
Apr 9, 2024
Messages
13
1712649933377.png


This is where i made the key!

I have 3 buttons in my form.
1. Is for the new record
2. Is for save the record that i created now
3. is for printing the report
 

June7

AWF VIP
Local time
Yesterday, 22:35
Joined
Mar 9, 2014
Messages
5,488
Did you create a macro or VBA? What does the button Click event property show? I don't use macros but macro commands can do this. If you prefer VBA, then select [Event Procedure] in the property and click the ellipses (...) to go to the event procedure in VBA editor.

I suggest you could benefit from a solid week with an introductory tutorial book.
 

soumelaki

New member
Local time
Today, 09:35
Joined
Apr 9, 2024
Messages
13
Ok but i dont know nothing of this. I dont know hoe to make macro or VBA.
But thank you for reply!!
 

soumelaki

New member
Local time
Today, 09:35
Joined
Apr 9, 2024
Messages
13
If this cant work! I thought i would try to make a button that prints the curent form with my record!
 

June7

AWF VIP
Local time
Yesterday, 22:35
Joined
Mar 9, 2014
Messages
5,488
You used the wizard to make something - either macro or VBA. Do you even know how to view Properties?

Printing forms is not a good idea. Not only do they not print nicely, still have to apply filter.
 

June7

AWF VIP
Local time
Yesterday, 22:35
Joined
Mar 9, 2014
Messages
5,488
Yes you can add filter criteria to that macro. That's what Where Condition is for.

But as I said, need to first commit record to table. So use the SaveRecord macro command. It needs to be positioned before the OpenReport command.

Look at some tutorials on building macros. I am not going to try to teach you these basics here.
 

Gasman

Enthusiastic Amateur
Local time
Today, 07:35
Joined
Sep 21, 2011
Messages
14,366
I would start learning vba, not macros.
Plenty of examples out there then.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 02:35
Joined
Feb 19, 2002
Messages
43,371
@June7 gave you the TWO lines of code you need in post #2.

When you click on the build button to the right of your button's click event you get three options (unless you set a default to code which you should). Pick code. Then just copy and paste the two lines of code and adjust the names as appropriate.

BUT FIRST, rename the button to something like cmdPrntRpt

That way your code module will be created with a nice name and when you look at the code you won't have to figure out what Command153 means.
 

June7

AWF VIP
Local time
Yesterday, 22:35
Joined
Mar 9, 2014
Messages
5,488
I provided guidance on creating VBA procedure in posts 2 and 6.

Modifying existing macro should be elementary.
 

soumelaki

New member
Local time
Today, 09:35
Joined
Apr 9, 2024
Messages
13
@June7 gave you the TWO lines of code you need in post #2.

When you click on the build button to the right of your button's click event you get three options (unless you set a default to code which you should). Pick code. Then just copy and paste the two lines of code and adjust the names as appropriate.

BUT FIRST, rename the button to something like cmdPrntRpt

That way your code module will be created with a nice name and when you look at the code you won't have to figure out what Command153 means.
Yes I made the button for test. Sure the name will be “Print Report”.
But first I have to learn how to create this macro and “build event”
 

Users who are viewing this thread

Top Bottom