By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,493 Members | 1,351 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,493 IT Pros & Developers. It's quick & easy.

Cascading Combo boxes in a subform in datasheet view

P: 4
I've used Access for some time but nver had to use any code. Ive a problem getting combo boxes to cascade in a sub form, I've done some searches and the problem appears to be in the identifaction of the relevant elements. I've been mucking around with a sample database and it has the following code in an event procedure
the main form is Form1
the subform is Bound Combo form

Expand|Select|Wrap|Line Numbers
  1. Private Sub Category_AfterUpdate()
  2. Product = Null
  3. Product.Requery 
  4. Product = Forms![Form1].[Bound Combo Form].Form.Product.ItemData(0)
  5. End Sub
  6.  
  7. Private Sub Form_Current()
  8. Forms![Form1].[Bound Combo Form].Form.Product.Requery
  9. End Sub
  10.  
  11. Private Sub Form_Load()
  12. If IsNull(Category) Then
  13.   Category = Forms![Form1].[Bound Combo Form].Form!ItemData(0)
  14.   Call Category_AfterUpdate
  15. End If
  16. End Sub
Cheers
Cliff
Feb 15 '12 #1
Share this Question
Share on Google+
7 Replies


NeoPa
Expert Mod 15k+
P: 31,186
Have a look through Cascaded Form Filtering. It should help.
Feb 15 '12 #2

P: 4
Had a look at this but it'snot quite what I need.
Ineteresting non the less.
Thanks
Cliff
Feb 16 '12 #3

NeoPa
Expert Mod 15k+
P: 31,186
If you're working in Datasheet view, then there are elements of the form which won't work. Controls are disabled in many ways, and just the underlying fields are used in a basic way.
Feb 16 '12 #4

P: 4
I rehashed it and changed the form to Continuous forms and managed to get the 2nd combo box working OK but cant figure out the 3rd level. This code is in the After Update event procedure in the 1st combo box DTCode
Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2.  
  3. Private Sub DTCode_AfterUpdate()
  4. DTCodeSub = Null
  5. DTCodeSub.Requery  'Forms![MainForm].[SubForm].Form.Requery
  6. DTCodeSub = Forms![Ftimesheet].[FDT].Form.DTCodeSub.ItemData(0)
  7. End Sub
  8.  
  9. Private Sub Form_Current()
  10. Forms![Ftimesheet].[FDT].Form.DTCodeSub.Requery
  11. End Sub
  12.  
  13. Private Sub Form_Load()
  14. If IsNull(DTCode) Then
  15.   DTCode = Forms![Ftimesheet].[FDT].Form.ItemData(0) 'Form! changed to Form.
  16.   Call DTCode_AfterUpdate
  17. End If
  18. End Sub
Feb 16 '12 #5

NeoPa
Expert Mod 15k+
P: 31,186
Please check out [code] Tags Must be Used.

Certainly Continuous Forms makes more sense to my way of thinking. You should understand though, that posting code is not a substitute for explaining your situation clearly. The code refers to various items that we have no clues about, so it's pretty tough trying to interpret what it is you're trying to ask (read: should be asking).
Feb 16 '12 #6

P: 4
Hi again
Sorry about that I havent had any experience of using VB so am kinda at sea here. All the work I've done in the past has been with queries etc.
What I'm trying to do is analyse the downtime on complex machinery, to this end I'm creating a from with 3 combo boxes linked to 3 tables
TDTCodeMain with fields IDmain incrementing and DTmain
TDTCodeSub with fields IDSub incrementing, IDmain and DTSub
TDTCodeSubSub with fields IDSubSub incrementing, IDSub and DTSubSub
I'm able to get the 2nd combo box to work ok, but the 3rd one is proving to be a we bit o a nuisance. I've tried applying the same code and SQL statements in the Row Source(with the names revised) to Combo boxes 2 & 3 but just get error messages galore, I'm abviously missing the trick here.
Thanks
Feb 17 '12 #7

NeoPa
Expert Mod 15k+
P: 31,186
I don't seem to be getting my point across very clearly. Let me try again.

To be able to help you, we need a question explained clearly (preferably in the first post, but otherwise at least all in one post). Dropping clues of one form or another into posts now and again, with no common thread of explanation, doesn't make something we can help you with. I know that's quite hard for a lot of people (from observation if nothing else), but imagine yourself on the other side trying to make sense of a situation with such sparse information and explanation.

If you are having problems with any code, and you already have the pre-requisite of an explanation that puts the code into perspective, then you must follow the guidelines in Before Posting (VBA or SQL) Code. Trust me. This will save you time in the long run ;-)

My problem at this stage is that I have very unclear ideas as to the context your question even fits within. Answering detailed questions about such a situation puts me at an enormous disadvantage - hence my inability to help.
Feb 18 '12 #8

Post your reply

Sign in to post your reply or Sign up for a free account.