473,396 Members | 1,743 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.

Linking a report to a form?

Hi there

I don't have a lot of programming experience (apart from google searching everything and a bit in Crystal) but Access just throws me!

I'm trying to link a record from a report to the same record in the form.
I have been looking in multiple forums trying to find a fix and can't seem to duplicate it correctly.

The most recent one I've tried is:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Description_Click()
  2.  
  3.  Dim EntityName As String
  4.  Dim Docname As String
  5.  
  6.  Docname = "frmDelivery Details"
  7.  Filtername = "qryDelivery Details"
  8.  
  9.  strWhere = "[frmDelivery Details].[DD_ID] = 'Me.DD_ID'"
  10.  DoCmd.OpenForm Docname, acNormal, Filtername, strWhere
  11.  
  12. End Sub
Which asks for frmDelivery Details.DD_ID parameter value, then returns a Run-time error 2501

Both the form and the report are based on qryDelivery Details. Does that need to be linked in somehow?

I have attached the database (apologies if there are any other bad practices in there...)and would be very appreciative of any help!
Attached Files
File Type: zip DSS Database.zip (635.2 KB, 107 views)
Aug 27 '13 #1

✓ answered by zmbd

Lets start by correcting Line 9:
strWhere = "[frmDelivery Details].[DD_ID] = 'Me.DD_ID'"
It is malformed.
If you will place:
debug.print strWhere
Immediately after Line 9, run the code, press <ctrl><g> in the window that opens you more than likely will see:
"[frmDelivery Details].[DD_ID] = 'Me.DD_ID'" instead of the desired:
"[frmDelivery Details].[DD_ID] = 'ControlValue_Str'"


Change Lets start by correcting Line 9:
strWhere = "[Field from your Recordset here] = '" & Me.DD_ID & "'"

-- This suposes that Me.DD_ID is a text/string.
If it is numeric and the field it refers to is set numeric then remove the single quotes
If it is a Date/time then replace the single quotes with the hash ( " # " )
-- [Edit{We also need to correct "[frmDelivery Details].[DD_ID] should be changed to reflect the desired field in your record set...post#4}]


Also, please understand, we do not normally open un-requested attachments. A practical example as to why can be found in a most recent post. This unfourtunate Member open a file from a trusted source and is now haveing all sorts of issues! http://bytes.com/topic/access/answer...ll-ms-products

4 3536
zmbd
5,501 Expert Mod 4TB
Lets start by correcting Line 9:
strWhere = "[frmDelivery Details].[DD_ID] = 'Me.DD_ID'"
It is malformed.
If you will place:
debug.print strWhere
Immediately after Line 9, run the code, press <ctrl><g> in the window that opens you more than likely will see:
"[frmDelivery Details].[DD_ID] = 'Me.DD_ID'" instead of the desired:
"[frmDelivery Details].[DD_ID] = 'ControlValue_Str'"


Change Lets start by correcting Line 9:
strWhere = "[Field from your Recordset here] = '" & Me.DD_ID & "'"

-- This suposes that Me.DD_ID is a text/string.
If it is numeric and the field it refers to is set numeric then remove the single quotes
If it is a Date/time then replace the single quotes with the hash ( " # " )
-- [Edit{We also need to correct "[frmDelivery Details].[DD_ID] should be changed to reflect the desired field in your record set...post#4}]


Also, please understand, we do not normally open un-requested attachments. A practical example as to why can be found in a most recent post. This unfourtunate Member open a file from a trusted source and is now haveing all sorts of issues! http://bytes.com/topic/access/answer...ll-ms-products
Aug 27 '13 #2
My apologies, I won't attached unless requested in future.

I've tried to fix as you've explained and it is still asking for parameters?

It now reads:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Description_Click()
  2.  
  3.  Dim EntityName As String
  4.  Dim Docname As String
  5.  
  6.  Docname = "frmDelivery Details"
  7.  
  8.  strWhere = "[frmDelivery Details].[DD_ID] = " & Me.DD_ID & ""
  9.  Debug.Print strWhere
  10.  DoCmd.OpenForm Docname, acNormal, , strWhere
  11.  
  12. End Sub
The DD_ID is a primary key from the original table, which holds the main delivery details information.
Aug 27 '13 #3
zmbd
5,501 Expert Mod 4TB
silly me....
I missed another error in the code:
strWhere = "[frmDelivery Details].[DD_ID] = " & Me.DD_ID & ""

"[frmDelivery Details].[DD_ID]" needs to refer to the field in your record set not to the field on your form.

Why don't you take a look at the following document and see how parameter queries work with reports. It works thru a simple example...
Using parameters with queries and reports
The method here hasn't changed since v97/2003 thru to v2010.
If you get stuck on something there, post back and we'll get it cleared up.
Once again, sorry I missed that other issue. :(
Aug 27 '13 #4
You are a lifesaver! It's all working now.

Thank you so much for all your help!!
Aug 28 '13 #5

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

Similar topics

1
by: El_Embozador | last post by:
Hi , please can you tell how i can print an MS ACCESS Report form visual basic, i ned a sample code .. Thanks
1
by: Peter | last post by:
Dear all, Could you give me a hint? a) I generate a report from a query table, then I want to use this report to show the total numbers of the customers who buy the goods. There is a string...
0
by: Fercat | last post by:
Hi! I receive in an Outlook mail folder some custom forms that contain user defined fields (for example, Client Name, Contract Number...). The problem is that when I finish linking this folder...
1
by: Samuel | last post by:
Why my Crystal Report form works on the machine I installed VB.NET, not works on the machine without VB.NET? Thanks.
1
by: S. van Beek | last post by:
Dear reader, First of all a happy new year. In Report event there is the "On No Date" event but in a Form this event is not available.
3
by: Lennart Nielsen | last post by:
How can I access a textbox place on a Local Report? As far as I can see the Report is not "visible" from the main windows form. Lennart
0
by: neeraj | last post by:
Hi people's I developed One Windows application with some crystal Report I used my predefined crystal reports files for my application. I just take one crystal report viewer on form and set...
1
by: tterb | last post by:
Hi there, Im a little stuck here, my problem is im making a house insurance form where you enter data into the feilds and the calculations link back to create the end result amount i cant seem to get...
12
by: Sol | last post by:
Hi gurus, I work for an oil company and need to fix an old DB, which used to work once. It will help us poor operators to do a safer job. What it does: When maintenance on a vessel is planned, the...
1
by: kkshansid | last post by:
i have some crystal reports but no related forms i made new simple form and copy pasted contents of a crystal report form to this new form and changed Dim Report As New CrystalReport6 according to...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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
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
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,...

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.