UtterAccess.com
Thank you for your support!      
X   Site Message
(Message will auto close in 2 seconds)

Welcome Guest ( Log In | Register )

 
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 Guru
Posts: 534



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

Access Wiki and Forums Moderator
Posts: 34,345
From: SoCal, USA



Try changing this line:

Me.cboLineItem.RowSource = sLineItemsSource

to

Me.jtblAPQPLineItems.Form.cboLineItem.RowSource = sLineItemsSource

HTH
Go to the top of the page
 
+
GirlGeek
post Oct 18 2007, 12:19 PM
Post #3

UtterAccess Guru
Posts: 534



:-( 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

Access Wiki and Forums Moderator
Posts: 34,345
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.
Go to the top of the page
 
+
JVanKirk
post Oct 18 2007, 12:38 PM
Post #6

UtterAccess VIP
Posts: 3,833
From: Fort Drum, NY



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
Go to the top of the page
 
+
JVanKirk
post Oct 18 2007, 12:41 PM
Post #7

UtterAccess VIP
Posts: 3,833
From: Fort Drum, NY



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 (IMG:http://www.utteraccess.com/forum/style_emoticons/default/thumbup.gif)
Go to the top of the page
 
+
GirlGeek
post Oct 18 2007, 01:30 PM
Post #8

UtterAccess Guru
Posts: 534



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 Guru
Posts: 534



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 Guru
Posts: 534



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 Guru
Posts: 534



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 Guru
Posts: 534



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,543
From: Texas (Is there anywhere else?)



VB does not have subforms. Is this an Access question?
Go to the top of the page
 
+
GirlGeek
post Oct 18 2007, 02:59 PM
Post #14

UtterAccess Guru
Posts: 534



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,543
From: Texas (Is there anywhere else?)



Access uses VBA, I'll move this to an Access Forum.
Go to the top of the page
 
+
JVanKirk
post Oct 19 2007, 07:32 AM
Post #16

UtterAccess VIP
Posts: 3,833
From: Fort Drum, NY



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
Go to the top of the page
 
+

Reply to this topicStart new topic

 



RSS Go to Top  ·  Lo-Fi Version Time is now: 4th February 2012 - 10:55 PM