UtterAccess.com

Welcome Guest ( Log In | Register ) · View New Posts · View Unanswered Topics

 
Reply to this topicStart new topic
> Cascading Combo Boxes in Main and Sub Form
 
   
GirlGeek
post Oct 18 2007, 12:06 PM
Post #1

UtterAccess Veteran
Posts: 394



I have a code question.

I have two tables:

Main jtblAPQP
Sub jtblAPQPLineItems

In the main I have two cascading combo boxes: Section and Subsection. In the sub I have Line Items.

When I choose Section, Subsection populates with only the appropriate subsections. I want to do the same for the line items in the sub so that when a subsection is chosen, ONLY the appropriate line items populate the combo box. This worked PERFECTLY as long as all combo boxes were on the same form. However, they aren't on the same form now and the AFTERUPDATE event of the Subsection cannot find the line item combo box. Follow?

Here's the AfterUpdate code of the Subsection combo box.

Private Sub cboSubsection_AfterUpdate()

Dim sLineItemsSource As String

sLineItemsSource = "SELECT [tlkpLineItems].[lngLineItemsID], " & _
" [tlkpLineItems].[lngSubsectionID], " & _
" [tlkpLineItems].[strLineItem] " & _
" FROM tlkpLineItems " & _
" WHERE [lngSubsectionID] = " & Me.cboSubsection.Value
Me.cboLineItem.RowSource = sLineItemsSource
Me.jtblAPQPLineItems.cboLineItem.Requery

End Sub

Where / How do I tell it to look in the subform for Me.cboLineItem.RowSource?
Go to the top of the page
 
+
theDBguy
post Oct 18 2007, 12:17 PM
Post #2

UtterAccess VIP and Access Wiki Moderator
Posts: 21,055
From: SoCal, USA



Try changing this line:

Me.cboLineItem.RowSource = sLineItemsSource

to

Me.jtblAPQPLineItems.Form.cboLineItem.RowSource = sLineItemsSource

HTH


--------------------
Microsoft Access MVP 2009-2010
Go to the top of the page
 
+
GirlGeek
post Oct 18 2007, 12:19 PM
Post #3

UtterAccess Veteran
Posts: 394



:-( Didn't Work. Neither does:

jtblAPQPLineItems.Form.cboLineItem.RowSource = sLineItemsSource

or

Me.jtblAPQPLineItems.cboLineItem.RowSource = sLineItemsSource
Go to the top of the page
 
+
jasonlewis
post Oct 18 2007, 12:26 PM
Post #4

UtterAccess Veteran
Posts: 201



Me.jtblAPQPLineItems.SubFormName.Form.cboLineItem.RowSource = sLineItemsSource

SubFormName=name of your subform
Form = Literal ... leave it as Form -)

Hope this is useful,

Jason
Go to the top of the page
 
+
theDBguy
post Oct 18 2007, 12:32 PM
Post #5

UtterAccess VIP and Access Wiki Moderator
Posts: 21,055
From: SoCal, USA



See if this link helps. Good luck.

Try:

Me!jtblAPQPLineItems.Form.cboLineItem.RowSource = sLineItemsSource



Edited by: theDBguy on Thu Oct 18 13:35:32 EDT 2007.


--------------------
Microsoft Access MVP 2009-2010
Go to the top of the page
 
+
JVanKirk
post Oct 18 2007, 12:38 PM
Post #6

UtterAccess VIP
Posts: 3,715
From: Northumberland, Pennsylvania



I think after Form you need to have the ! instead of the .

so it should look like:

Me.jtblAPQPLineItems.Form!cboLineItem.RowSource = sLineItemsSource

Sometimes the Me. doesn't always work right however so you might need to change it to:

Forms!YourMainFormName.jtblAPQPLineItems.Form!cboLineItem.RowSource = sLineItemsSource

J


--------------------
Jason VanKirk

If I had Superman powers everything would be easier
Go to the top of the page
 
+
JVanKirk
post Oct 18 2007, 12:41 PM
Post #7

UtterAccess VIP
Posts: 3,715
From: Northumberland, Pennsylvania



GG,

You probably should have posted this in Access Forms instead of Visual Basic. The code behind your forms, like for this combo box, is actually VBA, Visual Basic for Applications. Hope all is going well thumbup.gif


--------------------
Jason VanKirk

If I had Superman powers everything would be easier
Go to the top of the page
 
+
GirlGeek
post Oct 18 2007, 01:30 PM
Post #8

UtterAccess Veteran
Posts: 394



Okay, just got back from lunch. Will try the suggestions and post back!
Go to the top of the page
 
+
GirlGeek
post Oct 18 2007, 01:41 PM
Post #9

UtterAccess Veteran
Posts: 394



Yours worked, Jason V. Thank You!!! I have other issues but this particular one is solved. ;-)
Go to the top of the page
 
+
GirlGeek
post Oct 18 2007, 01:45 PM
Post #10

UtterAccess Veteran
Posts: 394



Okay, I think I know why I am having a new issue.

Here's the code:

Private Sub cboSubsection_AfterUpdate()

Dim sLineItemsSource As String

sLineItemsSource = "SELECT [tlkpLineItems].[strLineItem], " & _
" [tlkpLineItems].[lngSubsectionID], " & _
" [tlkpLineItems].[lngLineItemsID] " & _
" FROM tlkpLineItems " & _
" WHERE [lngSubsectionID] = " & Me.cboSubsection.Value
Me.fsubPQPLineItemsNew.Form.cboLineItem.RowSource = sLineItemsSource
Me.fsubPQPLineItemsNew.Form.Requery

End Sub

The red code: Is this wanting me to now point BACK to the main form? Same problem in reverse???
Go to the top of the page
 
+
GirlGeek
post Oct 18 2007, 01:50 PM
Post #11

UtterAccess Veteran
Posts: 394



YIPPEE! That wasn't it, after all. I had the wrong column bound in the Subsection part. Thanks to EVERYONE!!!! YAY!
Go to the top of the page
 
+
GirlGeek
post Oct 18 2007, 01:53 PM
Post #12

UtterAccess Veteran
Posts: 394



Darn. Every little victory met with another stinking error message.

This time it perfectly limited my line items but when I Saved Record, I got this error:

You cannot add or change a record because a related record is required in table tlkpLineItems - Original.

As far as I knew, I wasn't even using this dumb table.

Phooey.
Go to the top of the page
 
+
truittb
post Oct 18 2007, 02:22 PM
Post #13

UA Editor + Utterly Certified
Posts: 13,530
From: Texas (Is there anywhere else?)



VB does not have subforms. Is this an Access question?


--------------------
"Fiat Lux"
יְהִי אוֹר
"Bonum vinum laetificat cor hominis"
"Si Vis Pacem, Para Bellum"


--- No Bull ---
Utter Access Moderator
Microsoft Access MVP 2007 - 2010
Go to the top of the page
 
+
GirlGeek
post Oct 18 2007, 02:59 PM
Post #14

UtterAccess Veteran
Posts: 394



Yes. Sorry. Thought I could post VB questions here as it is VB wtihin Access.
Go to the top of the page
 
+
truittb
post Oct 18 2007, 03:19 PM
Post #15

UA Editor + Utterly Certified
Posts: 13,530
From: Texas (Is there anywhere else?)



Access uses VBA, I'll move this to an Access Forum.


--------------------
"Fiat Lux"
יְהִי אוֹר
"Bonum vinum laetificat cor hominis"
"Si Vis Pacem, Para Bellum"


--- No Bull ---
Utter Access Moderator
Microsoft Access MVP 2007 - 2010
Go to the top of the page
 
+
JVanKirk
post Oct 19 2007, 07:32 AM
Post #16

UtterAccess VIP
Posts: 3,715
From: Northumberland, Pennsylvania



GG,

Check your relationships. Whatever table you are writing to in thos form, it probably has a relationship with tlkpLineItems with referential integrity enforced.

In all of yout tables, I would check foreign keys. When you create the foreign key field and assign it's type as Number, it automatically sets a default value of 0. Remove the 0's in all of your foreign key fields.

J


--------------------
Jason VanKirk

If I had Superman powers everything would be easier
Go to the top of the page
 
+

Reply to this topicStart new topic

 



RSS Lo-Fi Version Time is now: 30th July 2010 - 11:20 AM

Tag cloud: