I have a button on my form that creates a print preview of my report. I can not get it to open on the same record as the current form. Instead it opens to the first record. They are both on the same query. I tried both macros and VBA. I'm new to access and cant understand how to get my records to be the same and print preview just the record I had open in my form
Here's my VBA code,I get error saying "no messsage for this error"
DoCmd.OpenReport "Moisture", acViewPreview, , "[Order Number]= " & [Order Number]
Try:
DoCmd.OpenReport "Moisture", acViewPreview, , "[Order Number]=""" & [Order Number] & """"
This may not be the best way but i solved this issue by creating a query for the report that only displayed the record source that was open with in my form. I passed the following in my criteria for my primary key in the query.
[Forms]![NameOfForm]![PrimaryKey]
thus only displaying that specific fields for that Primary key opened in the form and nothing else.
Related
I am making a query that feeds information into a report in MS Access. I have a search function that uses "*" & [Form]![FormName]![ComboBox] & "*" in one of the fields and is linked to a search box - this all works fine. However, I also have a button that opens the complete report - every time I click this button it asks for the parameter of the search box. I know this is happening because that's the criteria the query is based on. I'm just wondering if there is a way to get Access to ignore this criteria if the "Open Complete Report" button is pressed?
Thanks for your help.
What you need to do is decouple this report from the FormName form.
To do that, remove the "*" & [Form]![FormName]![ComboBox] & "*" condition from your query, and then pass a WHERE clause when you open the report using DoCmd.OpenReport.
For your form with the combobox, it would look something like this:
DoCmd.OpenReport "SomeReport", acViewNormal, , "SomeField = " & "*" & [ComboBox] & "*"
And for your "Open Complete Report" button, it would simply be
DoCmd.OpenReport "SomeReport", acViewNormal
I have a form and in the form is a sub form that displays rows from a query. One of the columns in the subform is the DNANumber. The report works 100%. Problem is, when I call the report using the following code,
strWhereClause = "[DNANumber]=" & strText
DoCmd.OpenReport "Certificate", acViewPreview, , strWhereClause, , acHidden
I get a popup message asking for the parameter value, also displaying that exact value it is looking for above the textfield. I have checked all the spelling in the queries, forms , subforms and tables and controlls. Everything is fine. Why do I get this popup message. Further, If I type in the value, it displays the report without a problem.
If [DNANumber] is text data type, add quotes around the value of strText when you build strWhereClause.
strWhereClause = "[DNANumber]='" & strText & "'"
I have an access 2010 report that pulls from a query. The query has a Date, Name, and ID. What I'd like is a drop down box at the top of the report that filters on Date. So when a user selects a date, the report would refresh and show the results form the query for that date only. I can't seem to get this to work and need some direction.
Thanks in Advance!
You can open a report with arguments.
DoCmd.OpenReport ReportName, View, FilterName, WhereCondition, _
WindowMode, OpenArgs
( http://msdn.microsoft.com/en-us/library/office/bb238032(v=office.12).aspx )
This means that you can create a form using the MS Access form wizards and either add a combobox that shows all available dates, or just a textbox formatted to accept dates and use that as the basis of a where statement. Add a button to run the report and set the click event to something like:
DoCmd.OpenReport "ReportName", acViewPreview, , _
"MyDate=#" & Format(Me.txtDate,"yyyy/mm/dd") & "#"
I have a form which allows the user to edit the properties of a filter via some combo boxes, then open a report. The report is opened with
DoCmd.OpenReport rptName, acViewReport, , whereClause, acWindowNormal
'whereClause = "Building = '005'" for instance
Some reports open fine, by which I mean they populate with the filtered info. Others, however, even though they are based off the same in-house template, IGNORE the filter all together and display a report based on ALL data (not the filtered data).
Why would a report ignore the filter? When I edit the reports in design mode after opening them with the form:
Working Report | Non Working Report
Filter: Building = '005' | Filter:
Filter On Load: No | Filter On Load: No
What could be causing the non-working report to not register the filter argument? There's no On Load VBA, nor any VBA, in these reports (except for an Export to PDF and a close button which is copy-paste for each report).
EDIT
Should have checked before, this happens regardless of whether or not the query driving the report is empty (ie the filter is never applied to some reports, regardless of blankness)
Not sure if the code will help, but:
Private Sub btnOpenSummary_Click()
If IsNull(Me.cboSummary) Then
MsgBox "Please select a building for the SUMMARY report."
Exit Sub
End If
strCrit = "Building = '" & Me.cboSummary & "'"
MsgBox strCrit
survArray = getSurveyArray()
For Each Survey In survArray
DoCmd.OpenReport Survey, acViewReport, , strCrit, acWindowNormal
Next Survey
DoCmd.OpenReport "Total Summary", acViewReport, , , , Me.cboSummary
End Sub
My fault.. there was code which had for some reason been linefed all the way down the code page and out of view. There was an On Open which played with the Control Source. It ended up being useless (as the control source only needed to be set once, not every time) but it was disabling the filter for some reason. Anybody else who may have this problem:
Make sure the control source is not being altered in your VBA for the report.
Thanks to those that helped, sorry my information was wrong.
My OnOpen code:
Private Sub Form_Open(Cancel as Integer)
Me.RecordSource = Me.Name
End Sub
It takes the name of the report, which corresponds to a name of a query, and puts it as the recordsource. (I have about 40 reports done this way, so it's dependent on names to make it fast to duplicate for different items).
Removing this made it work perfectly using Access 2010. Not sure if this was a problem specific to my setup or what, but, this change directly fixed it.
This is not a direct solution, but rather a workaround which should almost certainly work. Instead of applying filtering to the report, dynamically change the report data source by passing the where clause as a parameter.
To open the report use:
DoCmd.OpenReport rptName, acViewReport, , , acWindowNormal, whereClause
Note that the whereClause string is being passed as the OpenArgs parameter.
Then in the report VB:
Private Sub Report_Open(Cancel As Integer)
On Error GoTo ReportOpenError
If Not(IsNull(Me.OpenArgs)) Then
Me.RecordSource = Replace(Me.RecordSource,";"," WHERE " & Me.OpenArgs & ";")
End If
Exit Sub
ReportOpenError:
MsgBox "Unable to open the specified report"
Cancel = 1
End Sub
This solution assumes the report RecordSource is defined as a semicolon terminated SQL query (not a query name) and the record source does not already contain any WHERE, GROUP BY, etc., clauses. In those cases, it may be easier to redefine the query from scratch.
This problem may also occur when a report is copied and re-purposed. I had a report that was working fine then made a copy of it and was no longer able to filter it.
Perhaps there is a glitch in Access that causes it to ignore the filter when the report is copied under certain circumstances.
Solution: Instead of copying and re-naming the report, try creating a new report, linking the data source, and copying the fields back into place. If you are dealing with a new report, try re-creating it.
I have a text field with a button that filters by a keyword in a form.
Private Sub Command93_Click()
Me.Filter = "(Review Like '*" & Me.Text94 & "*')OR (Status Like '*" & Me.Text94 & "*')"
Me.FilterOn = True
Me.Requery
End Sub
I then have a button that generates the report from that filter.
Private Sub Filter_Click()
DoCmd.OpenReport "rptName", acViewPreview, , Me.Filter
End Sub
The problem is that whenever I hit this button to generate the report, I get a pop up box asking me to Enter Parameter ID and it is asking this for review. If I take the review criteria out (by the way I have many more fields I just used review and status to illustrate the example) then the report generates without any pop up box. The review is part of a notinlist event which opens another form and stores that info in a table review, if that is relevant at all. The report will still generate when I click ok and leave the Enter Parameter ID box blank but I'd like to somehow bypass it for two reasons - the first being the fact that I need other people who are not familiar with access to be able to use it and the second is the idea that if I learn what is causing it I can understand the way access works better. Thanks.
Does your report have a field called Review? If not, you either need to change the recordsource of the report so it is joined with the table that has review, or change your filter so it refers to the field that the report has.