Link to home
Start Free TrialLog in
Avatar of SMP319
SMP319Flag for United States of America

asked on

Combo Box updating record

I am using a form to sort for results on a report. i.e, select a "department"

I have a bound Combo box on the form  that i use to select the criteria prior to running the report. i.e. Select Department 1 and only Department 1 items are displayed. Select Department 2 Department 2 is displayed.

This works fine.

When I close the form, the record prior to the selected record in the form is being updated with the last value in the combo box.

I DO NOT want to use this form to update any record, just select the criteria for the report.

I have tried to use an unbound combo box put it does not do the sorting in the report.

Any other options or code to prevent the Combo box from updating records?
Avatar of mbizup
mbizup
Flag of Kazakhstan image

You don't need to use bound controls for this.

If you have an unbound combo box for selecting departments, just use this code in a button click event:

Docmd.openreport "Myreport", acviewpreview,,"[Department] = '" & me.cbodepartment & "'"  '<--- for text dept

Or

Docmd.openreport "Myreport", acviewpreview,,"[Department] = " & me.cbodepartment  '<--- for numeric dept
SOLUTION
Avatar of pteranodon72
pteranodon72
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of SMP319

ASKER

I create a unbound combo box on  the form which i use to select the division (Changed from Department as mentioned above) and a button which i then added the folowign code.

Private Sub Division_Click()
DoCmd.OpenReport "Project Tasks", acViewPreview, , "[Division] = '" & Me.cbodivision & "'" '<--- for text Division

End Sub

I get and error message
Compile Error:
Method or data member not found.
It references  .cbodivision  part of the code as the error

The Second Suggestion above opened the report but did not yield any data. It appears the filter part is not working
<Method or data member not found.>

That means either that cboDivision is not the correct name of your combo box, or that the code is not on the same form as your combo box.

Double-check the Name property of your combo box, and ensure that you are running this code from a command button that resides on the same form as your combo box.
Both of our posts are essetially the same thing so you should be getting identical results if they are both being implemented properly.

Regarding not finding any records, that means that the reports recordsource does not contain any records that match the criteria you are sullplying.  Does the Department field in your report's record source actually include any records for the value you are selecting in the combo box?

If you can post a copy of your database, it may be easier to help troubleshoot.
Avatar of SMP319

ASKER

Here is my sample Database. the Form is the  "Division Selection Project report", Report is the "Project Tasks". I checked everything you had mentioned. the error is gone but now i get a report with no results.
Any thoughts?
Test.accdb
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of SMP319

ASKER

Can your code be altered to bring the report up in the report view? it is opening in Print preview.
Avatar of SMP319

ASKER

Answered my question . Changed "Preview" in the code to "Report". I am still learning :)
Excellent - and leaving that parameter blank will send it directly to the default printer :)

DoCmd.OpenReport "Project Tasks", , , "[Division] = '" & Me.cbodivision.Column(1) & "'"