473,509 Members | 2,900 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Filtering Report from form

5 New Member
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 called invoicing. I would like to be on the invoicing form and click a button saying view invoice, this then takes the invoice number from the form and filters out all the other invoices so only that 1 invoice is shown.

Details of the fields, forms and reports:
Report Details:
Report name: Invoicing
The invoice number field is called: Invoice Number

Form details:
Form name: Invoicing
The invoice number field is called: Invoice Number

I have tried putting the following code into the reports on open event procedure:

Private Sub Report_Open(Cancel As Integer)
Me.Filter = "Invoice Number = " & Form_Invoicing.[Invoice Number].Value
Me.FilterOn = True
End Sub

Can some one please help me.
Mar 28 '06 #1
2 1900
CaptainD
135 New Member
I assume you're using MS Access, I would (through the click event) pass the Invoice Number to a report query and create the report off of that, or, if you want to use a Filter, set up the report based off the same query.
(I placed mine in a Sub and call it from different forms and filter by selected choices)
'Calling print report sub
Expand|Select|Wrap|Line Numbers
  1. Call PrintReports("Form_01", sFilterBy, iFilterBy)
  2.  
Sub:
Expand|Select|Wrap|Line Numbers
  1. Private Sub PrintReports(sReportName As String, sFilterBy As String, iFilterField As Integer)
  2. Dim sFieldName As String
  3. On Error GoTo ErrHandler
  4.  
  5. Select Case iFilterField
  6.     Case 1
  7.         sFieldName = "Submitted = '"
  8.     Case 2
  9.         sFieldName = "ProgramSupervisor = '"
  10.     Case 3
  11.         sFieldName = "ProgramManager = '"
  12. End Select
  13.  
  14.      If sFilterBy = "All Request" Or sFilterBy = "" Then
  15.         DoCmd.Maximize
  16.         DoCmd.OpenReport sReportName, acPreview
  17.         DoCmd.RunCommand acCmdZoom75
  18.         'DoCmd.Maximize
  19.     Else
  20.          'DoCmd.OpenReport stDocName, acViewPreview, , sFilterBy
  21.         DoCmd.OpenReport sReportName, acViewPreview, , sFieldName & sFilterBy & "'"
  22.         DoCmd.RunCommand acCmdZoom75
  23.     End If
  24.  
  25.  
  26. Exit Sub
  27. ErrHandler:
  28.     MsgBox "Error printing reports, Error # " & Err.Number & ", " & Err.Description, vbOKOnly, "Error"
  29. End Sub
  30.  
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 called invoicing. I would like to be on the invoicing form and click a button saying view invoice, this then takes the invoice number from the form and filters out all the other invoices so only that 1 invoice is shown.

Details of the fields, forms and reports:
Report Details:
Report name: Invoicing
The invoice number field is called: Invoice Number

Form details:
Form name: Invoicing
The invoice number field is called: Invoice Number

I have tried putting the following code into the reports on open event procedure:

Private Sub Report_Open(Cancel As Integer)
Me.Filter = "Invoice Number = " & Form_Invoicing.[Invoice Number].Value
Me.FilterOn = True
End Sub

Can some one please help me.
Mar 28 '06 #2
gleave
5 New Member
Hi, yes I am using MS Access, I actually managed to figure out the code before I saw the post from CaptainD (Thanks anyhow). This is the code I ended up using:

Private Sub Command51_Click()
On Error GoTo Err_Command51_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Invoices"

stLinkCriteria = "[Invoice Number]=" & Me![Invoice Number]
DoCmd.OpenReport stDocName, A_PREVIEW, , stLinkCriteria

Exit_Command51_Click:
Exit Sub

Err_Command51_Click:
MsgBox Err.Description
Resume Exit_Command51_Click

End Sub
Mar 29 '06 #3

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

Similar topics

2
3634
by: Dalan | last post by:
Okay, I have worked on this and then some, but cannot seem to crack it. So if someone can straighten my code out, or suggest a new approach, then I'm all ears. Here goes: I have two tables - one...
5
3066
by: Richard | last post by:
Hi, I have a form that take some time to load due to many comboboxes and at least 8 subforms. When I filter or sort the main form I get an error message and then Access shuts down. They ask if...
1
2640
by: diskoduro | last post by:
Hi! I'm trying to get help to an unexpected problem that has appeared while I was writing a new application. I want to opeon a report of product sales by filtering previously from a listbox in a...
0
1717
by: Scott Loupin | last post by:
I've got two databases with similar data in them (WestSide and EastSide). I've set up two identical reports that is filtered by date and the client name. I'm using one form to do the filtering. ...
15
4385
by: Richard Hollenbeck | last post by:
I tried to ask this question before on the 14th of January but I never got a reply. I'm still struggling with the problem. I'll try to rephrase the question: I have a crosstab query with rows...
1
5227
by: mstery | last post by:
I have a report generated via an ID selection made in a dropdown on a form. The report filters by an on click event in a preview report button on the form. Everything in the report, including...
2
1874
by: Gerry Abbott | last post by:
Hi all. Im using a form's recordsource for a report. which works fine Me.RecordSource = Forms("frmdate01").Form.Controls("HoldLog").Form.Controls("frmHoldLog01").Form.RecordSource Ive got a...
8
13498
by: | last post by:
hi, i have a form on which a user can choose specific criteria such as dates etc, in order to filter the report that is called from the form. i do this by using the Where section of the...
3
1156
by: TS | last post by:
Hi all, In my windows form, I need the user to select a client name from a combo box and click on a button that opens another form having CRViewer showing the data for that client selected. I...
3
5371
by: paquer | last post by:
On my Main form I have a Command Button that opens a Subform in order to create a new Subform record. At this point I want the subform to show only the new record being created. Not all the...
0
7234
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
7412
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
7069
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
5652
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
4730
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
3216
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
3203
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1570
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
775
muto222
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.