473,473 Members | 1,936 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Open a Report to the Last Record and Only that Record

21 New Member
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 4586
jforbes
1,107 Recognized Expert Top Contributor
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
JamesHalko
21 New Member
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 Recognized Expert Top Contributor
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
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.