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.
Related
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.
I have a customers table in an MS Access 2010 database. I want to create a form with two subforms which together allow the users to select a customer and see more detail about the customer.
The customers table looks like:
CustomerID
FullName
Address
City
StateProvince
Other fields
The mainForm I created in design view by dragging CustomerListForm and CustomerDetailForm onto MainForm.
CustomerListForm is on left side and lets users filter customers from long list
Contains the following controls:
txtFilter textbox with embedded macro where = [LastName] Like [Forms]![CustomerListForm]![txtFilter] & "*"
FullName textbox and hidden CustomerID textbox which are bound to CustomersTable
CustomerDeatilForm located on right, with contents changing based on selection from CustomerListForm
If no customer selected from CustomerListForm, show default message
Else:
Show FullName, address, city, and stateprovince of customer selected from CustomerListForm
txtFullName set =[CustomersTable]![FullName], and so on for other fields
When I run my CustomerListForm separately, it does successfully allow a user to filter customer records by typing in a name. But that filtering ability goes away when I embed CustomerListForm in mainForm. Also, my filtered results in CustomerListForm do not contain any sort of links, which means that CustomerDetailForm does not seem to be able to identify which customer it should be outputting data about.
Can anyone show me how to set this up? I think if I get this much running, I will be able to fill in the blanks from other research that I am doing.
EDIT:
I see that the FullName textbox on CustomerListForm has an OnClick method. FullName is not editable in CustomerListForm. CustomerID is a hidden field alongside each record in CustomerListForm. I also see that there are multiple hyperlink settings in the format tab of the property sheet for the FullName textbox. Is there some way that the OnClick method of the FullName textbox can be used to send the CustomerID to CustomerDetailForm? Perhaps in a hyperlink?
The subforms are presumably linked to the parent form by CustomerID?
Remove this value from the LinkMasterID, LinkChildID properties of the subform control (in the parent form - as opposed to on the form properties of the subform itself)
Remove the macro, and create an AfterUpdate event for txtFilter, which finds the relevant data and displays it in the CustomerListForm; In addition to whatever other code is in this procedure, put
Dim CustID as Long: CustID = [get customerID from wherever it is]
... [your other code]
Me.Parent.LockCustomer CustID
In the outer form, add this in vba:
Public Sub LockCustomer(CustID as Long)
CustomerDetailForm.Form.RecordSource = _
"SELECT * FROM Customer WHERE CustomerID = " & CustID
End Sub
If you've customer details of any sort on the main form in addition to the subforms, and you want to show the details of the selected customer in the listform on both the main form and the detail subform, instead of setting CustomerDetailForm.Form.RecordSource, set Me.RecordSource & ensure that the LinkMasterID, LinkChildID properties of the Detail subform control are set to CustomerID.
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 a data entry/editing form with two combo boxes (Name and Group).
Each Group correlates to multiple names but each name is in only one group.
At the bottom of this form is a subform which is a continuous form
displaying a query of the associated table filtered based on an
unbound combo from which you select the group.
Basically, you choose which group you want to see and it displays a list of all the Names in that Group.
I want to make this form able to add and delete Names from the table (which it does with buttons already), but I also want to be able to select a Name from the subform and have the main form focus on that entry and auto fill the two bound combos.
And then from there I would like to be able to edit and save that entry or just delete the entry.
Similarly, I would like to be able to add a new entry without worrying about writing over a current entry. Access might do this automatically; if this is the case:
Is it even possible to edit an entry without deleting and then replacing it?
I also want to be able to select a
Name from the subform and have the
main form focus on that entry and auto
fill the two bound combos.
To do that, you can do a FindRecord on the main form's recordset, using the ID from the subform. The form will move to the correct record. From the subform's OnCurrent Event:
Forms!MyMainForm.Recordset.FindFirst "MyID = " & desiredRecordID
or
Forms!MyMainForm.Recordset.FindFirst "MyID = '" & desiredRecordID & "'"
Similarly, I would like to be able to
add a new entry without worrying about
writing over a current entry.
To do that, execute the following code:
DoCmd.GoToRecord acDataForm, "MyMainForm", acNewRec
Good day
Created Tables = Suppliers, Products
I created a form.I created a combo-box that displays all products of a particular company.
I need that combo-box that displays all products to have a check-box or any other control next to each product SO that I will be able to select more than one product.
Then how do i create a report of only the products checked.
....newbie
ms access 2007
Unfortunately that slick new multi-value drop down combo box with a check box included in the columns is not available from a programmer’s development point of view. (The ability to use this control for our own needs is rather becoming a frequent request these days - it is very slick contorl)
I’m not sure if others posters are confused or not aware of this new feature in access 2007. So it’s very natural that you’re asking for this ability to use this cool combo box feature to drive and feed parameters to a report.
Unfortunately without a lot of coding tricks and use a bound table for the selected values you can’t use that control. ( So it’s possible, but not easy).
The recommended approach in this case is to simply drop a list box on to your prompt form.
Make the first column of the listbo the primary key or so called product ID that’s used internally in your application. Make the 2nd second column the description that the user will see and select in the list box. (the wizard should make the first collumn lenght zero so that the product IDs are not seen by the user - if not you can set this manually after the wizard creates the list box for you).
You’ll then have to open up the form in design mode and change in the other tab of a list box to set and allow multi select=yes. This setting will allow the user to select more than one option in the list box.
You’ll then need to place a button on the form with the following code behind that button that takes the list of parameters or values from the list box and passes them to the report
Dim MySql As String
Dim MySelection As Variant
MySql = ""
If Me.lstProducts.ItemsSelected.Count > 0 Then
For Each MySelection In Me.lstProducts.ItemsSelected
If MySql = "" Then
MySql = "("
Else
MySql = MySql & " or "
End If
MySql = MySql & " ProductID = " & Me.lstProducts.Column(0, MySelection)
Next MySelection
MySql = MySql & ") "
End If
End If
Docmd.OpenReprot “nameOfRepor”,acViewPreview,,mySql
The above assumes your field for product id is ProductID