473,406 Members | 2,343 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,406 software developers and data experts.

Filtering Report from form

5
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 1897
CaptainD
135 100+
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
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
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
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
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
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
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
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
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
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
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
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
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
0
BarryA
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...
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
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
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
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
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...

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.