Solved

Requery combobox in datasheet view

Posted on 2000-03-23
5
1,545 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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
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.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

863 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

26 Experts available now in Live!

Get 1:1 Help Now