Reputation: 109
I need help with solving a problem of forms and reports. I need to create a form with a Combo box that selects companies with a button to view A REPORT with some values on that selected company from Combo box. How can I do this? I created the combo box and when I press the preview button it displays all the companies. Any suggestions?
Here is my VBA code:
Option Compare Database
Private Sub Button_Click()
'Forms!FormFirmKarnet.Visible = False
DoCmd.OpenReport "FirmKarnet", acViewPreview
End Sub
Private Sub Close_Click()
DoCmd.Close acForm, "FormFirmKarnet"
End Sub
Private Sub id_AfterUpdate()
Forms!FormFirmKarnet!Code_company = Forms!FormFirmKarnet!id.Column(1)
End Sub
Private Sub id_LostFocus()
Forms!FormFirmKarnet!code_company = Forms!FormFirmKarnet!id.Column(1)
End Sub
Upvotes: 0
Views: 6479
Reputation: 6852
In this case you can open the report with a where
filter:
DoCmd.OpenReport "reportname", acViewPreview, , "Company_ID = " & Me.comboBoxName
This presumes that your comboBox has an ID field as the bound column and the field is called Company_ID
in the query of the report.
The ComboBox does not need any more code for this, you might just have to check if anything is selected before opening the report.
Upvotes: 2