I am trying to open a report to view an invoice for a specific invoice number. I have looked on the net and todate have not been able to resolve my problem! Help please,
My code is: - DoCmd.OpenReport strReport, acPreview, ,
-
Forms!frmInvoiceQ.BuyersInvoiceNo = Me.Text296
Text296 holds the required invoice number on Forms!frmMainForm
The query used to provide the data (qryCreateInvoiceBuy) looks for [Forms]![frmInvoiceQ].[BuyersInvoice] to provide the filter (the invoice number), hopes this makes sense.
Thanks in anticipation
19 13716
What's the Record Source for the report? I believe the WHERE claus (Forms!frmInvoiceQ.BuyersInvoiceNo = Me.Text296) has to associate with the reports' record source. And the record source would not be a form....
NeoPa 32,556
Expert Mod 16PB
The more usual way of doing this is to design a report that CAN show ALL items. The underlying query would not be filtered in this case.
The report then has a filter applied when it is opened. The WhereCondition parameter (of DoCmd.OpenReport()) specifies the filtering to be applied.
What's the Record Source for the report? I believe the WHERE claus (Forms!frmInvoiceQ.BuyersInvoiceNo = Me.Text296) has to associate with the reports' record source. And the record source would not be a form....
The record source is a query(qryCreateInvoiceBuy) which looks for the filter (invoice no) the location of the invoice no being Forms!frmInvoiceQ.BuyersInvoiceNo = Me.Text296.
The more usual way of doing this is to design a report that CAN show ALL items. The underlying query would not be filtered in this case.
The report then has a filter applied when it is opened. The WhereCondition parameter (of DoCmd.OpenReport()) specifies the filtering to be applied.
If the record source of all data for the report comes via a query would your suggestion still be possible? I think that this is pretty much as I have it at the moment
NeoPa 32,556
Expert Mod 16PB
It certainly would. It doesn't sound like what you've got to me though.
In your setup you filter within the query itself (with a reference to form control). In the standard way the filter is applied on opening the report object.
It certainly would. It doesn't sound like what you've got to me though.
In your setup you filter within the query itself (with a reference to form control). In the standard way the filter is applied on opening the report object.
I think I should have mentioned that I am using SQL to run the docmd. When it is run I get a message box "Enter parameter Value" - "Forms!frmInvoiceQ.BuyersInvoice", the script I am using that gets this message is: - strReport = "rptInvoiceBuy"
-
-
DoCmd.OpenReport strReport, acPreview
I am struugling to get the relaevant Invoice number that I am asked for in the Message Box vis SQL
NeoPa 32,556
Expert Mod 16PB
I think we just found our way back to the beginning again.
I was talking about a version withOUT the reference in the underlying SQL, but with a WhereCondition in the OpenReport line instead.
I'm happy to answer any questions related to that.
Any possibility that you could give me an idea of the code I should use. I thought my original message was using the "Where" clause ie. DoCmd.OpenReport strReport, acPreview, , Forms!frmInvoiceQ.BuyersInvoiceNo = Me.Text29
(Forms!frmInvoiceQ.BuyersInvoiceNo = Me.Text29 = the "where" )
Thanks
NeoPa 32,556
Expert Mod 16PB
If you look at the first post you will see that the Forms... is a separate line (not a continuation).
The form of your WHERE clause is also invalid as the left-side of the "=" should refer to something from the record of your report's Record Source.
NeoPa 32,556
Expert Mod 16PB
Any possibility that you could give me an idea of the code I should use.
To help with this I would need to know the name of the field in your Record Source that you want to filter on.
Any possibility that you could give me an idea of the code I should use. I thought my original message was using the "Where" clause ie. DoCmd.OpenReport strReport, acPreview, , Forms!frmInvoiceQ.BuyersInvoiceNo = Me.Text29
(Forms!frmInvoiceQ.BuyersInvoiceNo = Me.Text29 = the "where" )
Thanks
Absolute simplest way is: - DoCmd.OpenReport "SomeReportName", acViewNormal,, "[FieldToFilerOn]= " & Me![SomeFieldOnSomeForm]
Where FieldToFilterOn is a field on the report, in your case InvoiceID or something and SomeFieldOnSomeForm would be your Text29.
Also make sure that there are no filters in the report's SQL Record Source. The bit that says "Criteria" in the Query Designer, where it sounds as if you have typed in a [Forms]![SomeField] statement.
Gaz.
NeoPa 32,556
Expert Mod 16PB
To help with this I would need to know the name of the field in your Record Source that you want to filter on.
It's also important for the WhereCondition parameter to know whether your invoice number field is numeric string to determine what, if any, delimiters to use.
It's also important for the WhereCondition parameter to know whether your invoice number field is numeric string to determine what, if any, delimiters to use.
Thanks Gaz and NeoPa!!
You have yet again pointed me in the right direction, and the problem has now been solved. It turned out to be a little more involved than I first thought as I had to direct the code dependant on the invoice being for the buyer or seller! I know this is of no matter to you guys but if you want me to post the script I will be happy to do so.
Again my thanks.
Bruce (UK)
NeoPa 32,556
Expert Mod 16PB
You're welcome Bruce :) Welcome to Bytes!
PS. Posting the solution is encouraged, as it enables others with similar problems to know that it was resolved and how.
-NeoPa (UK too)
My solution : - Dim strInvoice As String
-
Dim strInvoiceNo As String
-
Dim strReport As String
-
Dim strReportSell As String
-
Dim strBuyersInvoiceNo As String
-
Dim strSQL As String
-
Dim strSQL1 As String
-
Dim db As DAO.Database
-
Dim rs As DAO.Recordset
-
-
strBuyersInvoiceNo = Me.Text296
-
Set db = CurrentDb()
-
strSQL = "SELECT tblFaxedDealsBP.BuyersInvoiceNo FROM tblFaxedDealsBP WHERE tblFaxedDealsBP.BuyersInvoiceNo= " + "'" & strBuyersInvoiceNo & "'"
-
Set rs = db.OpenRecordset(strSQL, dbOpenDynaset)
-
-
On Error GoTo Sell_Invoice 'OnError occurs when no results are found in strSQL'
-
BuyInv = rs!BuyersInvoiceNo
-
strReportSell = "rptInvoiceSell"
-
strReport = "rptInvoice"
-
If Me.Text296 = BuyInv Then GoTo Buy_Invoice Else GoTo Exit_Invoice
-
-
Buy_Invoice:
-
DoCmd.OpenReport strReport, acPreview, , "[BuyersInvoiceNo] = " + "'" & strBuyersInvoiceNo & "'"
-
Set rs = Nothing
-
Set db = Nothing
-
Exit Sub
-
-
Exit_Invoice:
-
Set rs = Nothing
-
Set db = Nothing
-
Exit Sub
-
-
Sell_Invoice:
-
Set db = CurrentDb()
-
strSQL1 = "SELECT tblFaxedDealsBP.InvoiceNo FROM tblFaxedDealsBP WHERE tblFaxedDealsBP.InvoiceNo= " + "'" & strBuyersInvoiceNo & "'"
-
Set rs = db.OpenRecordset(strSQL1, dbOpenDynaset)
-
SellInv = rs!InvoiceNo
-
strReportSell = "rptInvoiceSell"
-
DoCmd.OpenReport strReportSell, acPreview, , "[InvoiceNo] = " + "'" & strBuyersInvoiceNo & "'"
-
Set rs = Nothing
-
Set db = Nothing
-
Exit Sub
I am sure the script could be cleaner but hey its working!
NeoPa 32,556
Expert Mod 16PB
Thanks for that Bruce :)
As you have posted that, may I give you a tip about code indenting :
Generally only ever indent code further in to indicate a change of some form.
That might be the indented code is all within an If statement. EG : - If A = B Then
-
'Equals code
-
Else
-
'Not equals code
-
End If
Other structures are also typically indented. It should help to indicate to the reader the structure of the code. There are different sets of rules that coders follow, but common to all is that it generally helps the reader to follow what's happening where.
Anyway, Welcome to Bytes!
NeoPa 32,556
Expert Mod 16PB
I decided it may be easier to understand my point if I reformatted your code in the style I use. See if that makes it easier for you to read. The breaks and the flow are easier to spot. - Private Sub ?????()
-
Dim strInvoice As String
-
Dim strInvoiceNo As String
-
Dim strReport As String
-
Dim strReportSell As String
-
Dim strBuyersInvoiceNo As String
-
Dim strSQL As String
-
Dim strSQL1 As String
-
Dim db As DAO.Database
-
Dim rs As DAO.Recordset
-
-
strBuyersInvoiceNo = Me.Text296
-
Set db = CurrentDb()
-
strSQL = "SELECT tblFaxedDealsBP.BuyersInvoiceNo " & _
-
"FROM tblFaxedDealsBP " & _
-
"WHERE tblFaxedDealsBP.BuyersInvoiceNo='" & strBuyersInvoiceNo & "'"
-
Set rs = db.OpenRecordset(strSQL, dbOpenDynaset)
-
-
On Error GoTo Sell_Invoice 'OnError occurs when no results are found in strSQL'
-
BuyInv = rs!BuyersInvoiceNo
-
strReportSell = "rptInvoiceSell"
-
strReport = "rptInvoice"
-
If Me.Text296 = BuyInv Then GoTo Buy_Invoice
-
GoTo Exit_Invoice
-
-
Buy_Invoice:
-
DoCmd.OpenReport strReport, acPreview, , "[BuyersInvoiceNo]='" & strBuyersInvoiceNo & "'"
-
Set rs = Nothing
-
Set db = Nothing
-
Exit Sub
-
-
Exit_Invoice:
-
Set rs = Nothing
-
Set db = Nothing
-
Exit Sub
-
-
Sell_Invoice:
-
Set db = CurrentDb()
-
strSQL1 = "SELECT tblFaxedDealsBP.InvoiceNo " & _
-
"FROM tblFaxedDealsBP " & _
-
"WHERE tblFaxedDealsBP.InvoiceNo='" & strBuyersInvoiceNo & "'"
-
Set rs = db.OpenRecordset(strSQL1, dbOpenDynaset)
-
SellInv = rs!InvoiceNo
-
strReportSell = "rptInvoiceSell"
-
DoCmd.OpenReport strReportSell, acPreview, , "[InvoiceNo]='" & strBuyersInvoiceNo & "'"
-
Set rs = Nothing
-
Set db = Nothing
-
Exit Sub
-
End Sub
Thanks for the advice, always welcome. Other than that OK?
Regards
NeoPa 32,556
Expert Mod 16PB
Other than that - just thanks for posting it :)
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Andrew |
last post by:
Hi All:
I am using Access2000 and I find that the command to open an Access report
in preview mode is very slow: DoCmd.OpenReport rptABC, acViewPreview, "",
""
The scenario is this:
- The...
|
by: Jonathan Goldman |
last post by:
Hi-
I have a relatively simple report that I open in an Access '97 VBA
procedure, using the
Docmd.OpenReport "rptName", acViewNormal
syntax. The problem is that doing this usually crashes...
|
by: Filips Benoit |
last post by:
Dear All,
DoCmd.OpenReport RPT_TEST, A_PREVIEW, QueryAsFilter doesn't work correctly
in A97 but works OK in A2K.
Is this a bug for A97 ?
Filip
|
by: LoopyNZ |
last post by:
Hi there,
I've converted an Access 97 front end to Access 2000, but when I try to
run a VBA DoCmd.OpenReport (e.g. DoCmd.OpenReport
"rpt_programme_listing") line, Access completely crashes...
|
by: news.onet.pl |
last post by:
Hello!
I have a question concerning to open the reports.
I know that DoCmd.OpenReport is a obsolete form of opening the reports, but
how to implement opening reports in VB using another VB code?...
|
by: enough2Bdangerous |
last post by:
access runtime error 3011 on docmd.openreport
--------------------------------------------------------------------------------
Access database (file format 2002-2003) generates reports with...
|
by: Simon |
last post by:
Dear reader,
The syntax for Docmd.OpenReport is:
OpenReport(ReportName, View, FilterName, WhereCondition, WindowMode,
OpenArgs)
Example
The following example prints Sales Report while...
|
by: robtyketto |
last post by:
Greetings,
I originally used a button on a from created via the button wizard (access 2007) to run my report which was based on a query.
Since I wanted to add some validation I removed the...
|
by: scottbouley |
last post by:
Maybe I'm missing something or perhaps there's another way to do this. I'm trying to allow the user to preview and print an invoice as they are exiting from the New Sale form. However, the preview...
|
by: gazza10001 |
last post by:
Hi
i hope you can help my company uses access and has modified for its needs usually what happens is you serach for the invoice by its number and then it brings all the information up such as...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
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: 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: 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,...
|
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...
| |