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?
Microsoft Access

Avatar of undefined
Last Comment
mbizup
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

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of SMP319
SMP319
Flag of United States of America image

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
Avatar of mbizup
mbizup
Flag of Kazakhstan image

<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.
Avatar of mbizup
mbizup
Flag of Kazakhstan image

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
SMP319
Flag of United States of America image

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
Avatar of mbizup
mbizup
Flag of Kazakhstan image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Avatar of SMP319
SMP319
Flag of United States of America image

ASKER

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

ASKER

Answered my question . Changed "Preview" in the code to "Report". I am still learning :)
Avatar of mbizup
mbizup
Flag of Kazakhstan image

Excellent - and leaving that parameter blank will send it directly to the default printer :)

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


Microsoft Access
Microsoft Access

Microsoft Access is a rapid application development (RAD) relational database tool. Access can be used for both desktop and web-based applications, and uses VBA (Visual Basic for Applications) as its coding language.

226K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo