Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Populating a sub form from a combo box selection

Posted on 2008-06-23
11
Medium Priority
?
470 Views
Last Modified: 2013-11-28
I'm currently using Access 2003, and the problem that I'm running into is that when I attempt to use the autoupdate command in the code snippet below, my subform says its 'Filtered', but nothing appears in the sub form.  I think the problem may lie in the fact that my combo box cboItemNum2 is actually pulling all of its values from our server SQL database, where the subform is gathering data from a local Access database.  Reason being, we're attempting to create a bill of materials inventory, and all of the parts are entered into one form, going to table 'tblBOMParts'.  Another form is meant to view all of these entered parts (called frmTestView).  Two combo boxes filter all known parts from our SQL database (first combo box selects all available classes, and once 'Class' is selected, then all of the parts for that class are displayed in the second combo box).  I want this second combo box, which is unbounded, to query the table tblBOMParts, and filter all of parts to equal the selection in the 2nd combo box.  Is there a parent-child relationship that I'm missing here?  When I first open frmTestView, a couple parts show up on the subform, even though nothing is selected.  I am really confused, and I don't know what's causing those couple parts to show up, and even more so, why nothing shows up when I make a selection.

Thanks,

Ryan
Private Sub cboItemNum2_AfterUpDate()
Me.sfmViewPart.Form.Filter = "BOMPartNum='" & Me.cboItemNum2 & "'"
Me.sfmViewPart.Form.FilterOn = True
End Sub

Open in new window

0
Comment
Question by:jdol2949
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
  • 3
11 Comments
 

Author Comment

by:jdol2949
ID: 21846752
UPDATE:      Ok, I had a parent-child relationship set.. which was causing nothing to show up.  But now my problem is 'How do I get the subform to not show the entire table tblBOMParts when I open the main form frmTestView?'  Currently, when I open the form, all data is displayed in the boxes below.  If you can answer this simple question, I will award all 500 points.
0
 
LVL 7

Expert Comment

by:Chrisedebo
ID: 21846821
Try putting the following line at the bottom of the after update snippet
Me.sfmViewPart.Requery

Open in new window

0
 
LVL 7

Expert Comment

by:Chrisedebo
ID: 21846828
Set the filter in design view to be BOMPartNum = ''
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:jdol2949
ID: 21846905
the filter for the sub form?  I applied the filter to the sub form and the main form, and even still, all of the parts in tblBOMParts are being displayed in the subform window.  I'd like it if nothing at all showed up in the sub form window until I make a selection from the two combo boxes on the main form.

Thank you,

Ryan
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 21846957
<I'd like it if nothing at all showed up in the sub form window until I make a selection from the two combo boxes on the main form.>

set the filtered record source of the subform in the afterupdate event of the the two combo boxes

you can load the subform with a query like this

select * from tableName where 1=0

0
 

Author Comment

by:jdol2949
ID: 21847046
Below is what my VB code currently looks like for the two combo boxes.  Please let me know what I need to change in order for the subform to be blank upon the opening the main form.
Private Sub cboItemNum2_AfterUpDate()
Me.sfmViewPart.Form.Filter = "BOMPartNum='" & Me.cboItemNum2 & "'"
Me.sfmViewPart.Form.FilterOn = True
Me.sfmViewPart.Requery
(I don't know how to make this correct) Me.sfmViewPart.RowSource = "select * from tblBOMParts where 1=0"
End Sub
 
Private Sub cboItemNum1_AfterUpdate()
    Me.cboItemNum2.RowSource = "SELECT ItemNmbr FROM [Item] WHERE [Class] = '" & Me.cboItemNum1 & "'"
End Sub

Open in new window

0
 
LVL 7

Assisted Solution

by:Chrisedebo
Chrisedebo earned 200 total points
ID: 21847165
Me.sfmViewPart.RowSource = "select * from tblBOMParts where 1=0"

should be

Me.sfmViewPart.RecordSource = "select * from tblBOMParts where 1=0"
0
 
LVL 120

Assisted Solution

by:Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1) earned 1800 total points
ID: 21847244
you don't set the recordsource of the subform with

select * from tblBOMParts where 1=0

in the afterupdate of the combo, you will not get anything

in the design view of the subform

place this in the Record Source on the Data tab

select * from tblBOMParts where 1=0

'*********

in the afterupdate of the combo change the record source of the subform with a filter

Private Sub cboItemNum2_AfterUpDate()
Me.sfmViewPart.RecordSource="select * from tblBOMParts where BOMPartNum='" & Me.cboItemNum2 & "'"

end sub


0
 

Author Comment

by:jdol2949
ID: 21847399
it's saying Compile Error:  member or method not found (something along those lines)
It refers to the afterupdate of cboItemNum2
Private Sub cboItemNum2_AfterUpDate()
Me.sfmViewPart.Form.Filter = "BOMPartNum='" & Me.cboItemNum2 & "'"
Me.sfmViewPart.Form.FilterOn = True
Me.sfmViewPart.RecordSource = "SELECT * FROM [tblBOMParts] WHERE [BOMPartNum] = '" & Me.cboItemNum2 & "'"
End Sub
 
Private Sub cboItemNum1_AfterUpdate()
    Me.cboItemNum2.RowSource = "SELECT ItemNmbr FROM [Item] WHERE [Class] = '" & Me.cboItemNum1 & "'"
End Sub

Open in new window

0
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 1800 total points
ID: 21847604
try this, remove the filteron and filter lines , you don't need them

Private Sub cboItemNum2_AfterUpDate()
Me.sfmViewPart.Form.RecordSource="select * from tblBOMParts where BOMPartNum='" & Me.cboItemNum2 & "'"

end sub
0
 

Author Closing Comment

by:jdol2949
ID: 31469771
Thanks guys.
0

Featured Post

What Is Blockchain Technology?

Blockchain is a technology that underpins the success of Bitcoin and other digital currencies, but it has uses far beyond finance. Learn how blockchain works and why it is proving disruptive to other areas of IT.

Question has a verified solution.

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

In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

718 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