I'm trying to filter a report using an on-click button in a form. The form has a text box called MemberName, and I would like the report opened from clicking the button to only show records where the report's MemberName is the same as the form's MemberName. I used the OpenReport macro with the following WHERE condition:
WHERE = [MemberName] = Reports![ReportABC]![MemberName]
However, the report shown after clicking the button shows blank records. How can I fix this? I know I can alternatively build parameter queries directly related to the report in order to filter it, but I would very much like to just filter the report by using command buttons. Thank you.
You want to filter for a value on your form, so you need to refer to that. And WHERE is implied in the WhereCondition parameter, son don't include that.
It could look like this:
DoCmd.OpenReport "rptMember", View:=acViewPreview, _
WhereCondition:="[MemberName] = Forms![yourForm]![MemberName]"
Related
I am creating a menu form and adding buttons to allow a user to search through other forms. But I want to be able to print queries based on my database tables, is there any buttons or way of doing this with my menu form?
Not sure what you want. You want to print query object? Yes, can do that, in VBA use DoCmd.OpenQuery - acViewNormal parameter goes direct to printer. But - Why not build a report? For report printing use DoCmd.OpenReport, again, acViewNormal goes direct to printer.
If you want the output filtered, query would have to use dynamic parameter in WHERE clause. This can be a popup input or reference to a control on form. For a filtered report, review How to filter report
I am using Access to print employee reports and I have built a search form to facilitate this and query these reports. I have detail and summary reports and I want to make it so I only have one button for the open report, preview report, and print report buttons, instead of one set for detail and one set for summary. Here are a couple of pictures to illustrate what I need.
This is what I have currently.
And this is what I want.
How can I configure the checkbox to open/preview/print out the detail if unchecked and summary if checked? Also I'd prefer to not use VBA code if possible - as managers who don't know code let alone Access very well will have to use this in the future.
Any help would be much appreciated!!!!!
You will have to use VBA for this in your OnClick event of the button:
Dim ReportName As String
If Me!CheckSummary.Value = True Then
ReportName = "NameOfNormalReport"
Else
ReportName = "NameOfSummaryReport"
End If
DoCmd.OpenReport ReportName
I have a report (ReportX) that I wish to open from two different forms (FormA and FormB) in my database. I wish to do this because FormA and FormB address different aspects of my data, even if they ultimately get to the same output. ReportX is based on data from QueryX.
The problem I have is that QueryX would ideally filter the data based on the current RecordID in the current form. But I don't know how to accomplish this. I'd like to design QueryX so that the criteria for RecordID is essentially CurrentForm!RecordID, but research suggests that I cannot do this. Must I make separate but otherwise identical queries and reports for each form? Or is there a way to use VBA to define the query criteria when I click on the OpenReportX command button?
I already tried using the WHERE condition in the OpenReport command:
DoCmd.OpenReport "ReportX", acViewPreview, ,"RecordID = " & RecordID
but that did not display the results I wished. I need the report header to display/print for each RecordID and the page count in the page footer to reflect only the current/total pages of the RecordID in question. (In other words, if record 1 is one page, record 2 is two pages and record 3 is three pages, then ReportX, when displaying the first page of record 2, should say "Page 1 of 2" and not "Page 2 of 6.") So being able to display and print a single record properly using record filters would also solve my problem.
Which is the least cumbersome/most possible solution?
You should be able to accomplish this using the WHERE condition argument when you open a report:
DoCmd.OpenReport "rptName", acViewPreview, ,"RecordID = " & Me!RecordID
In the case where a I need more control over a Report's recordsource than what the Where condition argument can do for me, I will set the Reports RecordSource to be blank (after designing the report). Next I write code create the correct SQL statement in the Open Report button's Click event, followed by code to open the report and pass in the SQL as an opening argument for the report.
Private Sub cmdOpenReport_Click()
Dim sSQL as string
sSQL = "SELECT * FROM tblWhatever WHERE RecordID = " & Me!RecordID
DoCmd.OpenReport "rptReportName", acViewPreview, , , ,sSQL
End Sub
Then in the report's Open event I write code to set the recordsource:
Private Sub Report_Open(Cancel As Integer)
If IsNull(Me.OpenArgs) = False Then
Me.RecordSource = Me.OpenArgs
End If
End Sub
If neither of those accomplish what you want then you have an issue of a different sort. It's a little difficult for me to understand why you need All Records to show up in the header but only one record in the detail area. And how you expect to accomplish this. You might be best off trying to write a query first that gives you the exact results that your looking for so you know that it can be done.
As a side note, I actually use very few saved queries in my designs. It's not that there's anything wrong with using them, as the option is there for your convenience. I frequently use raw SQL on both forms and reports and set the RecordSource to the SQL on the Form or Reports Open or Load events.
Yes you can point to form data items in a query, and subsequently use that query in a report. The forms need to be open before the report runs. As far as having a header for each record, that is controlled in the settings of the report and how it displays the data.
In the Field, or Critera you can use the format:
[Forms]![frm_Process_Candidates]![QuestionTemplate]
Where frm_Process_Candidates would be the name assigned to your form, and QuestionTemplate is either the name of a control on your form, or a field from the data source of your form.
If you have a sub-form, there will be another [Form] call in the middle there.
[Forms]![frm_Dropdown_Admin]![frm_Dropdown_Admin_Detail].[Form]![text22]
Access should figure it out from there.
I have to build an MS Access form that acts as a registration form for delegates of a conference. I have to print out a receipt acknowledging the delegate's details and payment and other details. I think I have to make a report for this. So I made a rough report containing the required fields and placed a button on the form that prints the report out. When I clicked on it for the first record, it displayed the details faithfully. However, when I navigated to the second record and did the same, it displayed the details of the first record again. What do I do? Also, how can I customise it to mimic a receipt's format? Like so:
"Received with thanks from Mr./Ms. , a sum of Rs." and so on and so forth?
You've probably attached the record source for the Report to the same table/query that you are using for the Form. When you open the Report, you'll actually have receipts for each record in the source table/query.
What I would do in this case, is add a filter to the Report, and filter the records to show the same record as is currently displayed on the form. You can do this when you open the Report. e.g.,
docmd.OpenReport "foo", acViewNormal, , "fooID = " & me.fooID
(note: you may have explicitly turn on filters in the report's parameters)
You can display a customised line like that by building up a string in the default valude for an unbound text box.
="Text" & "foo" & me.value & ""
Or you can set the text box's value on the fly, probably during the OnFormat event.
Or you can do that as part of the query you use to provided data to the report, and use a bound text box.
I want a Access parameter query to ask an user for a value (a location in this case). When I type [Enter location] in the Criteria field it works fine: I get a dialog box (Enter Parameter Value) with a textbox and my text (Enter Location). So far, so good. This works (the result also).
But now I want a dropdown/combobox (instead of a textbox ) for the user to pick a location. I made a form and type Forms![Form1]![CmbLocation] in the Criteria field.
Like this: http://office.microsoft.com/en-us/access/HA011170771033.aspx
But I still get a textbox (with the reference as textlabel).
What am I doing wrong? Has anybody any advice?
In addition to Albert's suggestion, you might want to make this work within the query itself, so that it's "bootstrappable." To do that, you'd have to write function that returns the value chosen in the combo box on the form. It would be something like this:
Public Function ReturnMyCriterion() As Variant
DoCmd.OpenForm "dlgGetCriterion", , , , , acDialog
With Forms!dlgGetCriterion
If .Tag <> "Cancel" Then
ReturnMyCriterion = Nz(!cmbMyCombo, "*")
End If
Else
ReturnMyCriterion = "*"
End With
Close acForm, "dlgGetCriterion"
End Function
(when opening a form with the acDialog switch, the code pauses as long as the form is open or visible; to get the value out of the combo box, you have to set the form's .Visible property to False. You could do this in the AfterUpdate event of the combo box, or in the OK button. You'd also want a Cancel button that set's the form's .Tag property to "Cancel" and then sets the form's .Visible property to False; this is all relatively a standard approach to working with dialog forms in Access).
You'd then make the criterion in your query be:
Like ReturnMyCriterion()
That is, assuming you want to return all records if no value is chosen in the combo box.
If you removed parameter form your query, and then re-typed in the above form exprsison into the query builder, then it should work.
So, in the query builder, in the criteria section just type in
[forms]![form1]![Combo4]
Make sure you have the right form name and control name of the combo box.
You should not need to type in anything else into the query builder. As mentoned, remove the old parameter prompt you previous had in the query builder.
Now, open the form, select the combo box, and now try opening the query, it should open without any prompts. Note this approach means that the form will have to be open, and the combo box will have be selected a value BEFORE you attempt to launch the query. So, if you basing a report on this query, then palce the button to launch the report on the same form as the one with combo box. This quite much ensures that the form will be open before you attempt to launch a query or report that is based on that query