Solved

Requery combobox in datasheet view

Posted on 2000-03-23
5
1,537 Views
Last Modified: 2008-03-17
I have a subform datasheet, with the following columns...

Category  Product  Price

Category and Product columns are both comboboxes.  The rowsource for Products depends on the selection in the catagory combobox, however when i requery the product combobox, it requeries for all records on the datasheet, not for the current record, causing data to 'disappear' from other records.

Is there a way to prevent this from happening?  I tried making the form in continious form view with the same results.  Please help!

Thanks,
Phoat
0
Comment
Question by:Phoat
  • 3
  • 2
5 Comments
 
LVL 9

Accepted Solution

by:
BrianWren earned 50 total points
ID: 2650068
You don't need to requery that box.

In the Afterupdate of the Category combo ptu the following, (presuming the products combo is named 'cboPrd'):


     Me!cboPrd.RowSource = "SELECT * FROM tblProducts WHERE [CategoryID] = " & Me!cboCat


When you set that RowSource, the combo will adapt itself without a requery.

Question?

Brian
0
 
LVL 1

Author Comment

by:Phoat
ID: 2650284
i did that also... but lets say i choose vegetables from the categories column.  The cboPrd column's rowsource will change and i'll be able to pick lets say tomatoes....

but when i goto the next record, and i choose fruit for the categories column, the products column updates its rowsource and the previous record's value disappears.  It changes the rowsource for ALL the records, not just the current one... Im in datasheet view, don't forget.

Phoat
0
 
LVL 1

Author Comment

by:Phoat
ID: 2650310
Ok i got it to work i think....

I'll let you know once i test it a bit

Phoat
0
 
LVL 9

Expert Comment

by:BrianWren
ID: 2650386
Using controls that will change, in datasheet or continuous form views is problematic.

When you change the RowSource, you change the definition of that type of control, for that form.  So they all change.  

I suspect that the underlying data in the table stays the same though...

I would really recommend swtching to single form view, and using the OnCurrent event as well to coordinate these two combos as you move from record to record...

Brian

0
 
LVL 1

Author Comment

by:Phoat
ID: 2651245
i got it work.... Thanks!

The problem was that i was requery-ing the cbo after changing the rowsource, so it would update the display and erase the entries that didn't meet the criteria in the underlying SQL.  It worked after i took out the requery method from the cbo.

Thanks again.

Phoat...
0

Featured Post

Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

Join & Write a Comment

Suggested Solutions

I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the Pā€¦
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now