473,396 Members | 1,940 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Open a Report to the Last Record and Only that Record

Hello Everyone,

I want a command button to open a report to the last record in my database and only that report. Right now My button opens up the rport and the report has the code:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Report_Load()
  2.      DoCmd.GoToRecord record:=acLast   
  3. End Sub
  4.  
When I try to open the report I get the error:
Run-time error '2105':
You can't go to the specified record.

I am an access rookie so not sure where to go from here.

Thanks for all your help.
May 21 '15 #1
3 4578
jforbes
1,107 Expert 1GB
DoCmd.GoToRecord is really only for Navigation on a Form or Query.

Typically, people use a WhereCondition for a DoCmd.OpenReport to open a Report and Filter it to only what they want to show. An example would be to Open a Report of Employee information to show only information for the Employee that is selected on a Form. I borrowed this example from Seth and it would limit a Report to only show information for the Employee with the ID that is stored in the Field or Control Named GetEmployeeID:
Expand|Select|Wrap|Line Numbers
  1. DoCmd.OpenReport ReportName:="Report_Name", View:=acViewPreview, WhereCondition:="EmployeeID = " & GetEmployeeID
  2.  
May 21 '15 #2
Okay so I am running into a problem understanding the end of line of code. right now I have,
Expand|Select|Wrap|Line Numbers
  1. Private Sub Command51_Click()
  2. DoCmd.OpenReport ReportName:="LastRecord", View:=acViewPreview, WhereCondition:="[ID]=" & [ID]
  3. End Sub
  4.  
I get the error "Data type mismatch in criteria expression"
May 21 '15 #3
jforbes
1,107 Expert 1GB
The WhereCondition is a SQL Where Clause which means that it should be written using SQL Syntax, which varies a bit on which datatype is being compared.

So if the [ID] Column in the database is Alphanumeric, it will need to be surrounded by Single Quotes if it is Numeric then the Single Quotes will cause an error. This is a common stumbling block when first starting out. It still bothers me. I would be happy to stuff everything into quotes and not worry about it, but it doesn't work that way.

If [ID] is an Alphanumeric Column, the Syntax is:
Expand|Select|Wrap|Line Numbers
  1. DoCmd.OpenReport ReportName:="LastRecord", View:=acViewPreview, WhereCondition:="[ID]='" & [ID] & "'"
if it is just Numeric then the Syntax is:
Expand|Select|Wrap|Line Numbers
  1. DoCmd.OpenReport ReportName:="LastRecord", View:=acViewPreview, WhereCondition:="[ID]=" & [ID]
Also, you might need/want to define your ID a bit differently. What you have, might work, but I think you'll find it a little work with:
Expand|Select|Wrap|Line Numbers
  1. DoCmd.OpenReport ReportName:="LastRecord", View:=acViewPreview, WhereCondition:="[ID]=" & Me!ID
Lastly, ZMDB would like to see things like this as he believes, and I agree, it is easier to troubleshoot:
Expand|Select|Wrap|Line Numbers
  1. Dim sTemp As String
  2. sTemp = "[ID]='" & Me!ID & "'"
  3. DoCmd.OpenReport ReportName:="LastRecord", View:=acViewPreview, WhereCondition:= sTemp 
May 21 '15 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Daniel Ng | last post by:
Thanks for the 2 guys how hep to to solve to count the number of recount in forum. I'm done wif that. Got 1 more question.. Example Record 1: ID 2 VALUE 2 Record 2: ID 3 VALUE 3 Record 3: ID 2...
6
by: vasilijepetkovic | last post by:
Hello All, I have a problem with the program that should generate x number of txt files (x is the number of records in the file datafile.txt). Once I execute the program (see below) only one...
10
by: Alain Guichaoua | last post by:
Good evening to all Here is my problem : I have a form with a subform. They are linked. When I open the form I would like the subform to reach its last record. I tried the method...
17
by: michel.ank | last post by:
Hi, I'm using the class PrintLines and my last record of page aren't with the borders. Somebody can help me? Thanks,
12
by: Orchid | last post by:
Hello all, I have different version of reports which used for different months. For example, I am using report version 1 up to September, but we have some design changes on the report for October,...
4
by: magmike | last post by:
I've created a report for the purpose of printing a one page summary of a record. Of course, when I created the report, it gives me a page on every record. Can I create a button to open that report...
2
by: DVDPNNZ | last post by:
Hi Guys, I need some help I have created a access database (2000) made a form to entered data and a report that prints out the results I have added a button to the form that when press saves the file...
1
by: =?Utf-8?B?UiBSZXllcw==?= | last post by:
Hi, I'm having an issue in my C#.NET desktop application where two or more people viewing/editing the same record (from SQL Server) keep overwriting each others changes. Is there a setting in...
2
by: Giggly | last post by:
I have an access database and I have a macro in it that has the folowing commands: GotoRecord - Next OpenReport - Report Name: Single Receipt - View: Print I want the OpenReport to print...
4
by: RadioWriter | last post by:
I'm working on building a database in Access 2013, and I'm coming across an error in a subroutine which checks to see if there are duplicate entries in the field PartNumbers (and marks a True/False...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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...
0
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,...

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.