Show only the last record when previewing a report

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi All,

I am half way to the answer on this put can't work out the last part.
I have a form which is used to insert data into a table, when I click the
insert button the table is updated and then a report is opened to dislpay the
data. Problem is the report displays all the records.

What I need it to do is only display the record that was just entered.

I have tried using the gotorecord function but Access tells me I can't use
this in preview mode.

Any ideas?

Cheers,
Andrew
 
Hi Duane,

Thanks for the reply.

I have been trying this but I think the problem is my form is set to Data
Entry as I don't want any previous records to be displayed when opened.

Once I click the command button the tabel is updated but the form is cleared
so I don't think the ID value is being retained before the next part of the
VB is being run (does that make sense)?

How would I prevent the data from being "lost" before the below VB runs?

Cheers,
Andrew
 
Base your report on a query based on the table rather than basing your
report on the table. Include the primary key in your query. Put the
following expression in the criteria of the primary key field:
Forms!NameOfYourForm!NameOfThe PrimaryKey
 
FollanA said:
I am half way to the answer on this put can't work out the last part.
I have a form which is used to insert data into a table, when I click the
insert button the table is updated and then a report is opened to dislpay the
data. Problem is the report displays all the records.

What I need it to do is only display the record that was just entered.


Use the OpenReport method's WhereCondition argument to
filter the report's data.

Modify your code to include something like:

stWhere = "keyfield =" & Me.keyfield
DoCmd.Openreport "reportname", acViewPreview, , stWhere
 
Hi Marshall,

I have done exactly that but the problem I have now is that keyfiled always
equals null, resulting in an error.

Andrew
 
Ok, I have worked out I can get around this by adding a goto last record step
after the insert step, this just brings back the record into the field.

Thanks for everyones help.

Cheers,
Andrew
 
I might be able to make more specific suggestions if I could
see the code that you're using, but why not just save the
record's key field before saving the record? Then you
wouldn't have to mess with the form's normal activities.
 
Back
Top