473,511 Members | 12,087 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

filter a form (by record) to print preview or print report

imrosie
222 New Member
Hello,
I've gone through the tutorials, and searched. Still I can't find a clear solution to my issue.

I have a form with a subform that displays a listbox control called 'theOrderID'.
I have set it up (height 4") so that a long list of "saved" orders displays on the Form. The navigation works, so a person can scroll through the list of past orders.
I'm attempting to set up a way for the customer to search by date. (filter the past orders) and also to preview the order selected, and finally print.

I've got the code worked out for the listbox. The filter by date sort of worked out with a valuelist called 'filter' (today, this week, lastweek, etc.) and a macro.
I'm having the most difficulty with the preview and print.

The main form is bound to query "Invoices"; shows 3 fields (in valuelist), Customer Name, OrderID and OrderDate.

I have a Preview Button that calls a subroutine "Preview_Click---
Expand|Select|Wrap|Line Numbers
  1. Private Sub Preview_Click()
  2. Private Sub Preview_Click()
  3.     Dim strDocName As String
  4.     Dim strLinkCriteria As String
  5.  
  6. On Error GoTo ErrorHandler
  7.  
  8.     If IsNull(OrderID) Then
  9.         MsgBox "Please click an order in the list.", vbInformation
  10.     Else
  11.         Me.Visible = False
  12.         strDocName = "Invoice"
  13.         strLinkCriteria = "OrderID = " & OrderID
  14.         DoCmd.OpenReport strDocName, acViewPreview, strLinkCriteria
  15.     End If
  16.  
  17.     Exit Sub
  18.  
  19. ErrorHandler:
  20.     MsgBox "Error#:  " & Err.Number & vbCrLf & Err.Description
  21. End Sub
  22.  
I can't get it to work. Invoice is a Report I created. thanks for any directions.

Rosie
Aug 7 '07 #1
17 2391
kcachaler
3 New Member
Hello,
I've gone through the tutorials, and searched. Still I can't find a clear solution to my issue.

I have a form with a subform that displays a listbox control called 'theOrderID'.
I have set it up (height 4") so that a long list of "saved" orders displays on the Form. The navigation works, so a person can scroll through the list of past orders.
I'm attempting to set up a way for the customer to search by date. (filter the past orders) and also to preview the order selected, and finally print.

I've got the code worked out for the listbox. The filter by date sort of worked out with a valuelist called 'filter' (today, this week, lastweek, etc.) and a macro.
I'm having the most difficulty with the preview and print.

The main form is bound to query "Invoices"; shows 3 fields (in valuelist), Customer Name, OrderID and OrderDate.

I have a Preview Button that calls a subroutine "Preview_Click---
Expand|Select|Wrap|Line Numbers
  1. Private Sub Preview_Click()
  2. Private Sub Preview_Click()
  3.     Dim strDocName As String
  4.     Dim strLinkCriteria As String
  5.  
  6. On Error GoTo ErrorHandler
  7.  
  8.     If IsNull(OrderID) Then
  9.         MsgBox "Please click an order in the list.", vbInformation
  10.     Else
  11.         Me.Visible = False
  12.         strDocName = "Invoice"
  13.         strLinkCriteria = "OrderID = " & OrderID
  14.         DoCmd.OpenReport strDocName, acViewPreview, strLinkCriteria
  15.     End If
  16.  
  17.     Exit Sub
  18.  
  19. ErrorHandler:
  20.     MsgBox "Error#:  " & Err.Number & vbCrLf & Err.Description
  21. End Sub
  22.  
I can't get it to work. Invoice is a Report I created. thanks for any directions.

Rosie
-----------------------------------------------------------------

Try this:

strLinkCriteria = "OrderID = " & Me.OrderID

instead of

strLinkCriteria = "OrderID = " & OrderID
Aug 14 '07 #2
imrosie
222 New Member
-----------------------------------------------------------------

Try this:

strLinkCriteria = "OrderID = " & Me.OrderID

instead of

strLinkCriteria = "OrderID = " & OrderID
Hello Kcachaler,

I think that may be one I did try, but I may be wrong....so I'll give it a try. thanks so much.
Rosie
Aug 14 '07 #3
Scott Price
1,384 Recognized Expert Top Contributor
Hello Kcachaler,

I think that may be one I did try, but I may be wrong....so I'll give it a try. thanks so much.
Rosie
You'll likely need to do the same thing to your If IsNull() line... i.e. reference it to Me.OrderID instead of just OrderID (unless OrderID is a variable that you have declared elsewhere and are simply referencing here?)

Regards,
Scott
Aug 15 '07 #4
Scott Price
1,384 Recognized Expert Top Contributor
Just noticed also that your lines 1 and 2 are duplicates, you'll need to delete one of them.

Regards,
Scott

p.s. if you have more trouble, please elaborate on the statement, "I can't get it to work"... It's a little broad! :-)
Aug 15 '07 #5
imrosie
222 New Member
Just noticed also that your lines 1 and 2 are duplicates, you'll need to delete one of them.

Regards,
Scott

p.s. if you have more trouble, please elaborate on the statement, "I can't get it to work"... It's a little broad! :-)
OK Scott, I'm back, like a nightmare....I still can't get this thing to open an invoice.
Elaboration:

My form called PrintPreviewInvoices(PPI), is unbound. It contains a Listbox called thelistbox, that is based on row source table/query called Orderlist, (thelistbox has 3 columns; customer's name, orderid, orderdate). The bound column is 2 (orderid). This shows a list of past Orders in the Window.
There are also 3 command buttons on the PPI form; preview, print and cancel.
The preview button opens a predefined report called 'Invoice'. The goal is to have someone select and order and then to preview or print the order in the 'invoice' format. Invoice Reprot is bound to a query (invoices) as follows:

Invoice query (SQL):
Expand|Select|Wrap|Line Numbers
  1. SELECT Customers.CompanyName, [FirstName] & " " & [LastName] AS [Customer Name], Orders.OrderID, Orders.OrderDate, Orders.PurchaseOrderNumber, Orders.ShipDate, Orders.ShipMethodID, Customers.CustomerID, Orders.FreightCharge, Orders.SalesTaxRate, Orders.PurchaseOrderNumber, Customers.BillingAddress, Customers.City, Customers.ZIPCode, Customers.StateOrProvince, Customers.Country, Customers.PhoneNumber, Orders.ShipName, Orders.ShipAddress, Orders.ShipCity, Orders.ShipStateOrProvince, Orders.ShipCountry, Customers.ZIPCode, [Order Details].UnitPrice, [Order Details].Quantity, [Order Details].Discount, Products.ProductName, [Order Details].ProductID
  2.  
The Preview button code:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Preview_Click()
  2. Dim strDocName As String
  3. Dim strLinkCriteria As String
  4. On Error GoTo ErrorHandler
  5.  
  6. If IsNull(Me.OrderID) Then
  7. MsgBox "Please click an order in the list.", vbInformation
  8. Else
  9. Me.Visible = False
  10. strDocName = "Invoice"
  11. strLinkCriteria = "OrderID = " & Me.OrderID
  12. DoCmd.OpenReport strDocName, acViewPreview, strLinkCriteria
  13. End If
  14.  
  15. Exit Sub
  16. ErrorHandler:
  17. MsgBox "Error#: " & Err.Number & vbCrLf & Err.Description
  18.  
Next is the Print button:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Print_Click()
  2.     Dim strDocName As String
  3.     Dim strCriteria As String
  4.     Const conUserCancelledPrint = 2501
  5.  
  6. On Error GoTo ErrorHandler
  7.  
  8.     If IsNull(Me.[Orderlist].OrderID) Then
  9.         MsgBox "Please select an invoice from the list.", vbInformation
  10.     Else
  11.         Me.Visible = False
  12.         strDocName = "Invoice"
  13.         strCriteria = "[OrderID]= " & Me![OrderID]
  14.        'strLinkCriteria = "OrderID = " & OrderID
  15.         DoCmd.OpenReport strDocName, acViewNormal, , strCriteria
  16.     End If
  17.  
  18.     Exit Sub
  19.  
  20. ErrorHandler:
  21.     If Err.Number <> conUserCancelledPrint Then
  22.         MsgBox "Error#:  " & Err.Number & vbCrLf & Err.Description
  23.     End If
  24.  
I'm a newbie, but I think somewhere I should have the term 'thelistbox' in there. maybe that's the confusion. thanks and I hope I haven't overwhelmed you with the "elaboration".
Rosie
Aug 16 '07 #6
Scott Price
1,384 Recognized Expert Top Contributor
Expand|Select|Wrap|Line Numbers
  1. SELECT Customers.CompanyName, [FirstName] & " " & [LastName] AS [Customer Name], Orders.OrderID, Orders.OrderDate, Orders.PurchaseOrderNumber, Orders.ShipDate, Orders.ShipMethodID, Customers.CustomerID, Orders.FreightCharge, Orders.SalesTaxRate, Orders.PurchaseOrderNumber, Customers.BillingAddress, Customers.City, Customers.ZIPCode, Customers.StateOrProvince, Customers.Country, Customers.PhoneNumber, Orders.ShipName, Orders.ShipAddress, Orders.ShipCity, Orders.ShipStateOrProvince, Orders.ShipCountry, Customers.ZIPCode, [Order Details].UnitPrice, [Order Details].Quantity, [Order Details].Discount, Products.ProductName, [Order Details].ProductID
In this query, where are you setting the criteria that you want to see on the report?

like you say, it should capture the OrderID from the listbox that you are using to choose the order, right?

I think something along the lines of what you're looking for is a WHERE OrderID = thelistbox.Value statement to refine your query to just the one order you want to print (hope I'm understanding what you're wanting to do correctly!)

Regards,
Scott
Aug 16 '07 #7
imrosie
222 New Member
Expand|Select|Wrap|Line Numbers
  1. SELECT Customers.CompanyName, [FirstName] & " " & [LastName] AS [Customer Name], Orders.OrderID, Orders.OrderDate, Orders.PurchaseOrderNumber, Orders.ShipDate, Orders.ShipMethodID, Customers.CustomerID, Orders.FreightCharge, Orders.SalesTaxRate, Orders.PurchaseOrderNumber, Customers.BillingAddress, Customers.City, Customers.ZIPCode, Customers.StateOrProvince, Customers.Country, Customers.PhoneNumber, Orders.ShipName, Orders.ShipAddress, Orders.ShipCity, Orders.ShipStateOrProvince, Orders.ShipCountry, Customers.ZIPCode, [Order Details].UnitPrice, [Order Details].Quantity, [Order Details].Discount, Products.ProductName, [Order Details].ProductID
In this query, where are you setting the criteria that you want to see on the report?

like you say, it should capture the OrderID from the listbox that you are using to choose the order, right?

I think something along the lines of what you're looking for is a WHERE OrderID = thelistbox.Value statement to refine your query to just the one order you want to print (hope I'm understanding what you're wanting to do correctly!)

Regards,
Scott
Yes Scott, you do....that's exactly what I want to do...I tried a where statement, but I don't think I set it right,,,,so I took it out. But now reading what you've written, makes sense....

I'll give that a try and post back. thanks
Rosie
Aug 16 '07 #8
imrosie
222 New Member
Yes Scott, you do....that's exactly what I want to do...I tried a where statement, but I don't think I set it right,,,,so I took it out. But now reading what you've written, makes sense....

I'll give that a try and post back. thanks
Rosie
Hi Scott,

I set it to this:
Expand|Select|Wrap|Line Numbers
  1. WHERE Orders.OrderID = thelistbox.Value ORDER BY Customers.CustomerID;
Now when I attempt to open the PPI (PrintPreviewInvoices),,,it's asking me to give it a value. Normally when I open the form, the list is already there and I can simply select an order...any suggestions?
Aug 16 '07 #9
Scott Price
1,384 Recognized Expert Top Contributor
Hi Scott,

I set it to this:
Expand|Select|Wrap|Line Numbers
  1. WHERE Orders.OrderID = thelistbox.Value ORDER BY Customers.CustomerID;
Now when I attempt to open the PPI (PrintPreviewInvoices),,,it's asking me to give it a value. Normally when I open the form, the list is already there and I can simply select an order...any suggestions?
the PPI you are referring to is the report, or the form? In your second sentence you mention form. You have these two based on separate queries or one query?

Just to clarify, base the form on a query without WHERE criteria. Base the report on a separate query (it can be an exact copy of the first if you like, but make sure it's separate) The WHERE clause will go in the query for the report, not the form.

Regards,
Scott
Aug 16 '07 #10
Scott Price
1,384 Recognized Expert Top Contributor
Just making sure also that you have the right syntax in place in your WHERE statement? If I remember right you said this is on your subform? This will require the whole name in your WHERE statement, something like this: Forms![YourMainForm].[YourSubform].Form![ListBoxName].Value

Regards,
Scott
Aug 17 '07 #11
imrosie
222 New Member
Just making sure also that you have the right syntax in place in your WHERE statement? If I remember right you said this is on your subform? This will require the whole name in your WHERE statement, something like this: Forms![YourMainForm].[YourSubform].Form![ListBoxName].Value

Regards,
Scott
Scott hi, a slip of the typing....I didn't mean subform, actually 'thelistbox' is a control on the PrintPreviewInvoice form, it's not a subform. thanks

Rosie
Aug 17 '07 #12
imrosie
222 New Member
the PPI you are referring to is the report, or the form? In your second sentence you mention form. You have these two based on separate queries or one query?

Just to clarify, base the form on a query without WHERE criteria. Base the report on a separate query (it can be an exact copy of the first if you like, but make sure it's separate) The WHERE clause will go in the query for the report, not the form.

Regards,
Scott
Hi Scott,
The 'PrintPreviewInvoices(PPI)' is the form with the listbox, this form isn't bound, however the 'listbox' control on it is bound to the query Orderlist. The Report is bound to an Invoices query. Here is the Select query (with the where clause I tried) on the Report query called Invoices:
Expand|Select|Wrap|Line Numbers
  1. SELECT Customers.CompanyName, [FirstName] & " " & [LastName] AS [Customer Name], Orders.OrderID, Orders.OrderDate, Orders.PurchaseOrderNumber, Orders.ShipDate, Orders.ShipMethodID, Customers.CustomerID, Orders.FreightCharge, Orders.SalesTaxRate, Orders.PurchaseOrderNumber, Customers.BillingAddress, Customers.City, Customers.ZIPCode, Customers.StateOrProvince, Customers.Country, Customers.PhoneNumber, Customers.ShipName, Customers.ShipAddress, Customers.ShipCity, Customers.ShipStateOrProvince, Customers.ShipCountry, Customers.ShipZIPCode, [Order Details].UnitPrice, [Order Details].Quantity, [Order Details].Discount, Products.ProductName, [Order Details].ProductID
  2. FROM (Customers INNER JOIN Orders ON Customers.CustomerID=Orders.CustomerID) INNER JOIN (Products INNER JOIN [Order Details] ON Products.ProductID=[Order Details].ProductID) ON Orders.OrderID=[Order Details].OrderID WHERE Orders.OrderID = thelistbox.Value ORDER BY Customers.CustomerID;
  3.  
Obviously I'm doing something wrong....what's glaring at you? thanks
Rosie
Aug 17 '07 #13
Scott Price
1,384 Recognized Expert Top Contributor
Hi Scott,
The 'PrintPreviewInvoices(PPI)' is the form with the listbox, this form isn't bound, however the 'listbox' control on it is bound to the query Orderlist. The Report is bound to an Invoices query. Here is the Select query (with the where clause I tried) on the Report query called Invoices:
Expand|Select|Wrap|Line Numbers
  1. SELECT Customers.CompanyName, [FirstName] & " " & [LastName] AS [Customer Name], Orders.OrderID, Orders.OrderDate, Orders.PurchaseOrderNumber, Orders.ShipDate, Orders.ShipMethodID, Customers.CustomerID, Orders.FreightCharge, Orders.SalesTaxRate, Orders.PurchaseOrderNumber, Customers.BillingAddress, Customers.City, Customers.ZIPCode, Customers.StateOrProvince, Customers.Country, Customers.PhoneNumber, Customers.ShipName, Customers.ShipAddress, Customers.ShipCity, Customers.ShipStateOrProvince, Customers.ShipCountry, Customers.ShipZIPCode, [Order Details].UnitPrice, [Order Details].Quantity, [Order Details].Discount, Products.ProductName, [Order Details].ProductID
  2. FROM (Customers INNER JOIN Orders ON Customers.CustomerID=Orders.CustomerID) INNER JOIN (Products INNER JOIN [Order Details] ON Products.ProductID=[Order Details].ProductID) ON Orders.OrderID=[Order Details].OrderID WHERE Orders.OrderID = thelistbox.Value ORDER BY Customers.CustomerID;
  3.  
Obviously I'm doing something wrong....what's glaring at you? thanks
Rosie
Hi Rosie,

Just to be clear in my mind here again...

The query that populates the listbox is the one that's giving you the message asking for a value?

Does that other query have the same WHERE criteria as the query you have posted here?

I think I understood you saying that opening the form w/ listbox populated by the separate query, now asks you for a value...

Does it also do so on opening the report query after making a selection in the listbox?

What is the SQL for the listbox query?

Cheers!

Scott
Aug 17 '07 #14
imrosie
222 New Member
Hi Rosie,

Just to be clear in my mind here again...

The query that populates the listbox is the one that's giving you the message asking for a value?

Does that other query have the same WHERE criteria as the query you have posted here?

I think I understood you saying that opening the form w/ listbox populated by the separate query, now asks you for a value...

Does it also do so on opening the report query after making a selection in the listbox?

What is the SQL for the listbox query?

Cheers!

Scott
Hi Scott,
No, the query giving me the message is the Invoices query that supports the Invoice Report. When I run the report, it's asking for a value for the listbox. I believe your last post suggested that's where to place the 'Where' statement.

Here is the query for the listbox, it's called Orderlist:
Expand|Select|Wrap|Line Numbers
  1. SELECT DISTINCTROW [FirstName] & " " & [LastName] AS [Customer Name], Orders.OrderID, Orders.OrderDate, Customers.CustomerID
That's all it does in filll the listbox with all the past Orders.
No, there is no 'Where' statement in it as you can see.The Orderlist query supports the PrintPreviewInvoices Form (PPI) Are you suggesting that I put it in there as well? The Preview cmd button on the PPI form, is a 'Click' event, as well as the Print cmd button.

Does that clear things up more?
Rosie
Aug 18 '07 #15
Scott Price
1,384 Recognized Expert Top Contributor
Hi Scott,
No, the query giving me the message is the Invoices query that supports the Invoice Report. When I run the report, it's asking for a value for the listbox. I believe your last post suggested that's where to place the 'Where' statement.

Here is the query for the listbox, it's called Orderlist:
Expand|Select|Wrap|Line Numbers
  1. SELECT DISTINCTROW [FirstName] & " " & [LastName] AS [Customer Name], Orders.OrderID, Orders.OrderDate, Customers.CustomerID
That's all it does in filll the listbox with all the past Orders.
No, there is no 'Where' statement in it as you can see.The Orderlist query supports the PrintPreviewInvoices Form (PPI) Are you suggesting that I put it in there as well? The Preview cmd button on the PPI form, is a 'Click' event, as well as the Print cmd button.

Does that clear things up more?

Rosie
Thanks, Rosie, yes that clears things a little more...

No need to put the WHERE criteria in the listbox query. That would just break something else that we'd have to fix later :-)

Make sure in this line of your report query that you refer to thelistbox using it's full name: Forms![YourFormName].thelistbox.value

Expand|Select|Wrap|Line Numbers
  1. WHERE Orders.OrderID = thelistbox.Value
Should be:

Expand|Select|Wrap|Line Numbers
  1. WHERE Orders.OrderID = Forms![YourFormName].thelistbox.Value
Let me know if this works!

Regards,
Scott
Aug 18 '07 #16
imrosie
222 New Member
Thanks, Rosie, yes that clears things a little more...

No need to put the WHERE criteria in the listbox query. That would just break something else that we'd have to fix later :-)

Make sure in this line of your report query that you refer to thelistbox using it's full name: Forms![YourFormName].thelistbox.value

Expand|Select|Wrap|Line Numbers
  1. WHERE Orders.OrderID = thelistbox.Value
Should be:

Expand|Select|Wrap|Line Numbers
  1. WHERE Orders.OrderID = Forms![YourFormName].thelistbox.Value
Let me know if this works!

Regards,
Scott
Scott this is why you're the expert....YES it works....thanks for sticking with me..
Rosie
Aug 19 '07 #17
Scott Price
1,384 Recognized Expert Top Contributor
Scott this is why you're the expert....YES it works....thanks for sticking with me..
Rosie
Glad it works Rosie :-)

Good luck on the rest of your app.

Regards,
Scott
Aug 19 '07 #18

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

Similar topics

1
1212
by: MSDN | last post by:
When i tried to print preview/print it shows very small picutre representation... How i can scale the print preview...? Please help, Thanks. Aji.
7
14340
by: Pat | last post by:
I would like to send the Print Preview of a MS Access form to a Snapshot file. The form contains an OLE graph. BACKGROUND A snapshot of a report is possible. If I could I would use a report to...
0
2217
by: Malcolm Cook | last post by:
I've discovered: Using "File > Print Preview" in a form's datasheet view with a server Filter crashes access after previewing... ....that is, unless ServerFilterByForm has been turned off...
1
8563
by: Marty | last post by:
How do you print preview a crystal report in C#.NET? Thanks.
2
14104
by: Dean Slindee | last post by:
Anybody written code in VB.NET to: 1) show a print preview window of reports already written and stored in an Access 2002 database; or 2) execute the print of a report stored in an Access 2002...
1
2864
by: jj | last post by:
I created a dynamic report and the fields is displayed base on the query. The report contains about 34 fields so if the query has 34 fields, all 34 fields in the report shows up. But if the query...
7
3458
by: itm | last post by:
I have a mail out to send to a group of owners with multiple accounts. I want to limit the number of accounts that print on the first page to 20. I want remaining accounts to print on a second...
1
1901
by: hosi | last post by:
Hi, suppose I want to print third record from a subform. The problem is, that when I want to print what I see on my monitor (third record), the print preview resets the form to the first record...
1
2630
didajosh
by: didajosh | last post by:
Hi, I am working on a accounting report.it looks like ------------------------------------------------------------------------------------------- Group code (group by) Org Code(group by) ...
1
4412
by: RobT | last post by:
*sigh* I can't get this to work. My program fills all the values into an Excel spreadsheet- no problems there. What I'd like to do is a print preview/print function. I can't seem to get my code...
0
7356
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
7427
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
7085
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
7512
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
5671
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,...
1
5069
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
3227
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
3214
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
449
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.