UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> get the last record in subform    
 
   
jah_Access
post Jun 25 2009, 03:06 AM
Post #1

UtterAccess Enthusiast
Posts: 56



hi, is there a way of getting the last record in subform(datasheet view) and display it on report.

thanks a lot
Go to the top of the page
 
+
Steve Schapel
post Jun 25 2009, 03:41 AM
Post #2

UtterAccess VIP
Posts: 3,881
From: New Zealand



Jah,

Rather than thinking in terms of the "last" record in a subform, which is a very loose concept (because of the way the records on the subform happen to be ordered), it is better to try and identify the record you want by referring to the data it includes.

So what makes the "last" record last? Is there a date/time field, or an ID number of some sort, or some other way you can determine the last record?
Go to the top of the page
 
+
jah_Access
post Jun 25 2009, 03:43 AM
Post #3

UtterAccess Enthusiast
Posts: 56



because of the ID number
Go to the top of the page
 
+
Steve Schapel
post Jun 25 2009, 04:03 AM
Post #4

UtterAccess VIP
Posts: 3,881
From: New Zealand



Jah,

Ok, so I will suppose that your subform is based on a table or a query, maybe it's named YourTableOrQuery.

Make a query based on YourTableOrQuery and sort it descending on the ID field. And then set the query's Top Values property to 1. The SQL view of such a query will look something like:
SELECT TOP 1 ID, OneField, AnotherField, SomethingElse
FROM YourTableOrQuery
ORDER BY ID DESC;

Then make this query as the Record Source for your report.
Go to the top of the page
 
+
jah_Access
post Jun 25 2009, 04:14 AM
Post #5

UtterAccess Enthusiast
Posts: 56



yes i already did but the problem is displaying in a report, is this code right?

=forms!frm_mainform!frm_subform.field
Go to the top of the page
 
+
Steve Schapel
post Jun 25 2009, 04:23 AM
Post #6

UtterAccess VIP
Posts: 3,881
From: New Zealand



Jah,

I don't understand. Do you mean you are putting this expression in the Control Source of a textbox on the report? If you try to refer like this to the value of a control on a form, it will use the whatever happens to be the form's Current record. This will be unreliable to give you what you want. If you instead base the report back to the actual data, via a query based on your tables, and forget the form altogether, you will get a reliable result.

If I'm missing your meaning here, can you please give some more details and examples of what you are trying to achieve.
Go to the top of the page
 
+
jah_Access
post Jun 25 2009, 05:09 AM
Post #7

UtterAccess Enthusiast
Posts: 56



yes im putting the expression in the control source.. but the data in the form is actually from the table, could it be possible?

thanks steve

im just new in accesss :(
Go to the top of the page
 
+
Steve Schapel
post Jun 25 2009, 03:34 PM
Post #8

UtterAccess VIP
Posts: 3,881
From: New Zealand



Jah,

Best wishes with your forth-coming adventure with the wonderful world of Access! (IMG:http://www.utteraccess.com/forum/style_emoticons/default/sad.gif)

Yes, the data is always in the tables. Forms only provide a convenient way to view and interact with the data, but the data is not "in" the form. Same with a report... they are for the presentation of data, but the data stays in the table.

It is good to think of it like this.

Whereas it is possible to use an expression to reference a control on a form, and the value of the data (sourced from the table) by that control, and sometimes this is a useful approach. But it is usually simpler and more efficient in a case such as yours, to create a query that returns the data you want, and then base your form or report on that query, and forget about trying to cross-reference data from controls on another object (form or report).

Make sense?
Go to the top of the page
 
+
jah_Access
post Jun 25 2009, 07:53 PM
Post #9

UtterAccess Enthusiast
Posts: 56



thanks steve, but is there a way of getting ONLY the last record based on employeeID as reference?
Go to the top of the page
 
+
jah_Access
post Jun 25 2009, 08:30 PM
Post #10

UtterAccess Enthusiast
Posts: 56



HI STEVE THANKS FOR THE HELP, I ALREADY GOT THE IDEA OF SELECT TOP1 (IMG:http://www.utteraccess.com/forum/style_emoticons/default/sad.gif)

ALREADY WORKING

(IMG:http://www.utteraccess.com/forum/style_emoticons/default/sad.gif)
Go to the top of the page
 
+
Steve Schapel
post Jun 25 2009, 08:34 PM
Post #11

UtterAccess VIP
Posts: 3,881
From: New Zealand



Very good, Jah.

Good luck with the rest of the project!
Go to the top of the page
 
+

Thank you for your support! Reply to this topicStart new topic

Jump To Forum:
 



RSS Go to Top  ·  Lo-Fi Version Time is now: 18th May 2013 - 12:49 PM