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

Home Posts Topics Members FAQ

Open Filtered report from Hyperlink

2 New Member
I have got a report with a list of names and I want to make them hyperlinks, so that when clicked on they open another report in a window showing all the entries in the database filtered under their name.

I have tried using the DoCmd.OpenReport command and presently it just opens the report with a blank page.

Here is the code I have at the moment for the hyperlink:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Name_Click()
  2. DoCmd.OpenReport "Individual list", acViewPreview, , "[Name]= 'Me.Name'"
  3. End Sub
  4.  
I am sure it is just a silly error somewhere, but I cant seem to sort it!

Many thanks in advance.

Kieran
Jul 24 '13 #1

✓ answered by zmbd

Expand|Select|Wrap|Line Numbers
  1. Private Sub Name_Click() 
  2. DoCmd.OpenReport "Individual list", acViewPreview, , "[Name]= '" & Me.Name &"'" 
  3. End Sub
Need to enclose the string portion of the criteria so that the form control value is available.

You've hit on two issues here:

Access 2007 reserved words and symbols
"Name" is one such reserved word and might cause you some issues.

Second:
You've stumbled upon one of my pet peeves by building the criteria string within the command - and it's not your fault because that's how a majority of examples show how to use the command.
Instead I suggest that you build the string first and then use the string in the command. Why you might ask, because you can then check how the string is actually resolving; thus, making troubleshooting the code so much easier as most of the time the issue is with something missing or not resolving properly/as expected within your string.

Expand|Select|Wrap|Line Numbers
  1. (some code omited...)
  2. DIM strSQL as string
  3. '
  4. strSQL = "[Name]= '" & Me.Name &"'" 
  5. '
  6. 'now you can insert a debug print here for troubleshooting
  7. ' - press <ctrl><g> to open the immediate window
  8. ' - you can now cut and paste this information for review!
  9. '
  10. debug.print "Your criteria = " & strSQL
  11. '
  12. 'now use the string in your code:
  13. DoCmd.OpenReport "Individual list", acViewPreview, , strSQL

3 1361
zmbd
5,501 Recognized Expert Moderator Expert
Expand|Select|Wrap|Line Numbers
  1. Private Sub Name_Click() 
  2. DoCmd.OpenReport "Individual list", acViewPreview, , "[Name]= '" & Me.Name &"'" 
  3. End Sub
Need to enclose the string portion of the criteria so that the form control value is available.

You've hit on two issues here:

Access 2007 reserved words and symbols
"Name" is one such reserved word and might cause you some issues.

Second:
You've stumbled upon one of my pet peeves by building the criteria string within the command - and it's not your fault because that's how a majority of examples show how to use the command.
Instead I suggest that you build the string first and then use the string in the command. Why you might ask, because you can then check how the string is actually resolving; thus, making troubleshooting the code so much easier as most of the time the issue is with something missing or not resolving properly/as expected within your string.

Expand|Select|Wrap|Line Numbers
  1. (some code omited...)
  2. DIM strSQL as string
  3. '
  4. strSQL = "[Name]= '" & Me.Name &"'" 
  5. '
  6. 'now you can insert a debug print here for troubleshooting
  7. ' - press <ctrl><g> to open the immediate window
  8. ' - you can now cut and paste this information for review!
  9. '
  10. debug.print "Your criteria = " & strSQL
  11. '
  12. 'now use the string in your code:
  13. DoCmd.OpenReport "Individual list", acViewPreview, , strSQL
Jul 24 '13 #2
barter27293
2 New Member
Thanks for that - it was just the reserved word 'Name' that was causing the issue... sorry I'm not that experienced with access - just trying to pick it up as I go along!

thanks again :-)
Jul 25 '13 #3
zmbd
5,501 Recognized Expert Moderator Expert
Those nasty little keywords are a Gremlin for many people. The other is using spaces. Although technically allowed under the newer programs and operating systems, you'll find that if you need to upgrade to a larger database (SQLServer, MySQL, Oracle, etc...) that the spaces may also cause issues.


My Pleasure. We were all at the bottom of the learning curve at some point! Please keep us in mind should you get stuck again.
Jul 25 '13 #4

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

Similar topics

6
by: dog | last post by:
Does anyone know how to use a hyperlink in MS Access (I'm using 97) to open a report or form within the same database? I have a form in my database, I have put a label on it, some text, and when...
1
by: Gerry Abbott | last post by:
Hi all, The following code works to output a report myReport, to a file myFile, in ..snp format. --------- DoCmd.OutputTo acOutputReport, "MyReport", "Snapshot Format", MyFile ---------
6
by: erick-flores | last post by:
Hello, I want to make a report for a single compressor. Instead of showing a report for all the compressors. I would like to place a button in the compressor form, so whenever I want to display a...
2
by: Bob | last post by:
I have a regular C# form with a button on it. I want to click the button and open the report. What code do I need to open the report? Thanks-in-advance. Bob
3
by: samanta | last post by:
Hi all, I am using the following code to open a report from a datagrid. <asp:TemplateColumn HeaderText="Company Name"> <HeaderStyle Font-Size="Larger"...
0
by: Kelii | last post by:
Evenlater, Yeah, I don't open the report in preview mode when I setup my recordsource, filters, or sorts. Before I give my solution, I would say that your code will be simpler if you drop the...
3
by: Naushad | last post by:
Hi All, I am trying to open the report conditionally from the dialogue box form. In the form there are three field. cboEmployees StartDate EndDate I have used these field in criteria to...
0
by: sarvmardan | last post by:
how to open a report in access containing filtered data using two combo boxes on form and a button to click. let i have two fields and other is . two comboboxes are combo11 and combo9. plz post...
6
by: SusanK4305 | last post by:
Here are my two code for the Report that will be opened. This Report is in Access and is name rpt1, It isn't opening like it should. Please Help... Thank you. Private Sub cmdApplyFilter_Click() ...
0
by: Jason Hamilton | last post by:
Hey all, Okay, so here's what's going on. I have a customer who wants me to push the reports generated by MS Access to his corporate website on demand. I have most of this problem solved (by...
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
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...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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,...
0
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: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
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?

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.