I have been looking at YouTube for a month learning MS Access. I've created a MS Access report that displays all required info from three tables for 45 distinct systems in my inventory. I want to create a combobox so that the report is only generated for a specific system instead of all 45 as it is doing now. The data bases are joined by the data field called Acronym. I can create a form with a combobox with the acronym's displaying and can select the acronym in the combobox. I cannot figure out how to tie that specific acronym back to generate only the report for that acronym. The report is called RptSystemProfile.
The DoCmd.OpenReport has an optional WhereCondition parameter. you can do something like
DoCmd.OpenReport "RptSystemProfile", acViewPreview, _
WhereCondition := "SystemID=" & cboSystem.Value
This assumes that the system is identified by a column called SystemID (adapt it to reflect the real name). This column must be selected in the query the report is based on. It also assumes this column is a Long
If the column is a string then write
DoCmd.OpenReport "RptSystemProfile", acViewPreview, _
WhereCondition := "SystemID='" & cboSystem.Value & "'"
The also assumes that this Id is the BoundColumn column of the Access ComboBox.
You can have a ComboBox display a text but be bound to an id. The row source of the ComboBox would be a query similar to
SELECT SystemId, SystemName FROM tblSystem ORDER BY SystemName
Then set BoundColumn to 1 and ColumnWidths to 0cm. This hides the first column and displays only the text.
The Value property of the ComboBox then reflects the Id of the selected system.
Related
My question is a simple one, and I cannot find a simple answer to this question, after much searching. Many of the answers are about more complex coding situations that are difficult for me to relate to this question.
I am opening a report from a form. I can specify the username parameter as "bill" and the report displays only the records where "bill" is the user name. If I manually change "bill" to "tom" it still works and displays the records where the user name is "tom"
Private Sub Command11_Click()
Const cstrForm2 As String = "Report1"
'DoCmd.OpenReport cstrForm2, acViewPreview, WhereCondition:="[username]=" & "'bill'"
End Sub
If I use the following code, and put in Me.username (username being the name of the textbox, and is unbounded)
DoCmd.OpenReport cstrForm2, acViewPreview, WhereCondition:="[username]=" & Me.username
MS Access prompts me to enter the parameter value. If I enter the parameter value, "tom" or "bill" I get the correct data on the report.
How do I get rid of the parameter input box, basically how do I pass the correct format of parameter value to get the result I want? It may have to do with using a combination of quotes and other characters, I think.
The answer is to create a query first. Apparently creating a query avoids the problem.
Create a query for the table in question, and in the criteria section of the query, under design view :
enter the following under criteria
[Forms]![Form1]![username]
Where Form1 is the name of the form and username is the name of the textbox.
When you get the query running, create a report using the query as a basis.
You still need the single-quotes:
DoCmd.OpenReport cstrForm2, acViewPreview, WhereCondition:="[username]='" & Me!username.Value & "'"
I have been using MS Access to aid in generating pdf reports based on a table. I have created a form that contains a text box for entering a client's name (this value is in the main table) and a button that when clicked runs the code:
Private Sub cmdPrintRecord_Click()
Dim strReportName As String
Dim strCriteria As String
strReportName = "Current SP Report"
strCriteria = "[Owner]='" & Me![Owner] & "'"
DoCmd.OpenReport strReportName, acViewPreview, , strCriteria
End Sub
The idea here is to generate an individual PDF report based on the clients name.
The above procedure has been able to do that successfully however, I have encountered that as I run it, the data in my table is affected, specifically the client name field.
For example: I'll run a report for client "Anthony" and it shows 10 products which is correct, but then if I go back and run that same report again it will show 11 products. It is as if the procedure here is altering the data table.
How can I troubleshoot this issue and or are there any alternatives recommended?
Thanks.
Attached is the MS link where I obtained the source code:
https://support.microsoft.com/en-us/kb/209560
If the Control Source of a form control (textbox, combo box) is linked to a table then it will modify that table. In your case, you want to receive user input based on selections from a table and not to modify the table itself. You want to use the "Row Source" property to limit the selection to table items and clear the Control Source. This pulls potential options from the table without changing existing table entries.
Like this:
Notice that the source of options for the combobox is a query that defines what items should appear in the dropdown but no Control Source is specified.
I have almost finished a project and I would like some user options in the form.
I would like to allow the user to select a product code and when selected, it will find the relative record in the table and then display all the information from that in a report.
Any ideas on the best approach to this would help me out massively.
Use the combo box selection with DoCmd.OpenReport as the WhereCondition option.
So if the report's record source table or query includes a numeric field named product_code and your combo box is named cboProductCode ...
DoCmd.OpenReport "YourReport", _
WhereCondition:="[product_code] = " & Me.cboProductCode
If the field is text rather than numeric, add quotes around the value in the WhereCondition.
WhereCondition:="[product_code] = '" & Me.cboProductCode & "'"
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 created a form, displaying company.
created combo-box in the form to list all products of that company
with a check-box next to each item*(IN THE COMBO BOX). how do I create a report on only the items that were checked,
OR
soloution2, I tried showing all products of that company on that form in sub-data-sheet, with a checked box field. how do I create a report on only the items that were checked,
not very proficient in access...
thanks a MIL
In this article, Microsoft shows how to retrieve the values from a listbox as a string. This can then be used to create an SQL statement, for Openargs (depending on your version of Access) or as the WHERE argument for the report:
DoCmd.OpenReport "ReportName",acViewPreview,,"ID IN (" & ListOfIDs & ")"
Note that you will need quotes for a list of strings:
"A","List","Of","Strings"
But not for numbers:
1,2,3,4
This would be similar for the subform, but the best bet would be to build the sql statement and to use that as the Record Source:
strSQL="SELECT ID, SomeField FROM SomeTable WHERE ID IN (" & ListOfIDs & ")"
Me.[NameOfSubformControl].Form.RecordSource=strSQL
You might like to use a command button to do this.
Be sure to use the name of the subform control, not the the form contained.
It would be easier with a simple listbox that allowed only one company to be selected, because you could then set the Link Child (to the company ID) and Link Master (name of the listbox) fields for the subform control.
In both cases, it is best that the listbox is setup with two columns, Company ID and Company Name, with Company ID as the hidden, bound column.