Hello,
What im trying to do is to create a report from a form. I have made a template for the report i would like to use.
What i have is a form which contains details of a customer. What i would like to do is when on a certain customer to be able to view their details that are shown on the form to appear on a report which can be printed off.
What is the best way to be able to do this?
3 1193
Hi, there. I'll try to explain the basics of what you need to do.
First off you should have a query that youre basing your report off. This query should contain all the customer info you need. Something like this: -
SELECT customerID, customerFirstName, customerLastName, customerPhone, customerAddress, customerCity, customerProvince, customerPostalCode
-
FROM tblCustomer
-
Once you have your report created add a command button to your form. Under the onclick event of your command button you'll add code similar to this: -
Private Sub cmdPreview_Click()
-
-
Dim strLinkCriteria As String
-
Dim strDoc As String
-
-
strLinkCriteria = "[CustomerID] = " & Me.CustomerID
-
strDoc = "rptCustomerDetails"
-
-
DoCmd.OpenReport strDoc, acViewPreview, , strLinkCriteria, acWindowNormal
-
-
End Sub
-
Notes:- strLinkCriteria is a string we build to act as the where statement of the report
- strDoc is the report we want to open
- Docmd.OpenReport is the command used to open the report with our specified parameters
- if CustomerID is a text field rather than a number use this:
-
strLinkCriteria = "[CustomerID] = '" & Me.CustomerID & "'"
-
Give this a try and if you need any help or clarification I'd be more than happy to assist.
Jking
Hi, there. I'll try to explain the basics of what you need to do.
First off you should have a query that youre basing your report off. This query should contain all the customer info you need. Something like this: -
SELECT customerID, customerFirstName, customerLastName, customerPhone, customerAddress, customerCity, customerProvince, customerPostalCode
-
FROM tblCustomer
-
Once you have your report created add a command button to your form. Under the onclick event of your command button you'll add code similar to this: -
Private Sub cmdPreview_Click()
-
-
Dim strLinkCriteria As String
-
Dim strDoc As String
-
-
strLinkCriteria = "[CustomerID] = " & Me.CustomerID
-
strDoc = "rptCustomerDetails"
-
-
DoCmd.OpenReport strDoc, acViewPreview, , strLinkCriteria, acWindowNormal
-
-
End Sub
-
Notes:- strLinkCriteria is a string we build to act as the where statement of the report
- strDoc is the report we want to open
- Docmd.OpenReport is the command used to open the report with our specified parameters
- if CustomerID is a text field rather than a number use this:
-
strLinkCriteria = "[CustomerID] = '" & Me.CustomerID "'"
-
Give this a try and if you need any help or clarification I'd be more than happy to assist.
Jking
It is opening up the report but it isn't showing any of the data. The code i have used is:
Private Sub Command690_Click()
Dim strLinkCriteria As String
Dim strDoc As String
strLinkCriteria = "[ID] = ' " & "Me.ID ' "
strDoc = "Customer"
DoCmd.OpenReport strDoc, acViewPreview, , strLinkCriteria, acWindowNormal
End Sub
Try changing this line: -
strLinkCriteria = "[ID] = ' " & "Me.ID ' "
-
To: -
strLinkCriteria = "[ID] = '" & Me.ID & "'"
-
You can see the difference very well with the colours from the code tags.
Edit: I see now this was my fault as I was missing a & in my previous post. Sorry for the confusion.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Wayne Aprato |
last post by:
What can cause Access to bring up Runtime Error 2450 saying that it
can't find a particular form when the form is definitely open? I am
opening the form and then checking if fields are populated...
|
by: Paul Mendez |
last post by:
I have a form that consists of 150 records and is still growing.
there are times when I want to print a certain record of the form, say
record 12. I go to file --> print and choose the page number...
|
by: StBond |
last post by:
Hi everyone,
I am new to Access and Visual Basic so things my be getting across a
bit cloudy. I only started using VB for one week.
I am having a little problem with the database that I am...
|
by: ThompsonJessical |
last post by:
I am trying to use a button with the vba coding for SendObject Function
to email a specific report based on the value of another field of the
current record.
The form is a continuous form and...
|
by: gleave |
last post by:
Hi. im trying to setup a filter for a report. Let me explain what I would like to achieve. I have a form called Invoicing, here all the data is put in about the invoice, I then have a report also...
|
by: Incolor |
last post by:
Hello All!
I have to generate a checklist form as an input form in Access. A paper
form is taken out in the field and checked yes, no, OR n/a for each
item inspected. The problem I am having is...
|
by: melnhed |
last post by:
---Report the current filtered records from a Form---
Hello All,
I've seen this topic discussed before, but the solution described then
doesn't work in my particular case.
My Config: ...
|
by: radink |
last post by:
Hey All,
I have a report that I would like to show a word on based on if a
field is checked in a form. For example. The form has a check box
called Fee. If that is checked, I want the word Paid...
|
by: phill86 |
last post by:
Hi,
I am filtering a report using the form filter with the following code
DoCmd.OpenReport "report1", acViewReport, , Me.filter
Which works fine untill I filter the form on one of the...
|
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
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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...
|
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...
|
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: 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...
| |