Connecting Tech Pros Worldwide Forums | Help | Site Map

Another Multiple Combo box Question

Newbie
 
Join Date: Nov 2006
Posts: 25
#1: Jun 22 '07
Hi Everyone,

I have a form set as a dialog box with 2 Combo boxes (Combo0 & Combo4) and 2 text boxes (text8 & text10).

The form's record source is set to a table named Customers.

Combo0's row source is set to a query conatining the Customer Name Field in Customers

Combo4 lists only the citys of whaterver customer is picked from combo0.

Text10's control source is the state field in customers
Text8's control source is a unique ID field in customers.

When you choose a customer name in combo0 and then a city in combo4 text10 & text8 become visible and dsplay the related state and unique ID for that location.

My problem is that if there is more than one customer in the same city my code only returns the state(Text10) and unquie ID(Text8) for the first match that it comes to in the table.

Here's the code of combo0 AfterUpdate:
Expand|Select|Wrap|Line Numbers
  1. Dim wclause
  2.  
  3.     [Combo4].Visible = True
  4.  
  5.     wclause = "SELECT Customers.CITY FROM Customers WHERE customers.[company name]=[combo0];"
  6.     [Combo4] = " "
  7.     [Combo4].RowSource = wclause
Here's the code from Combo4 AfterUpdate:
Expand|Select|Wrap|Line Numbers
  1. Dim rs As Object
  2.  
  3.     Set rs = Me.Recordset.Clone
  4.     rs.FindFirst "[CITY] = '" & Me![Combo4] & "'"
  5.     If Not rs.EOF Then Me.Bookmark = rs.Bookmark
  6.  
  7.     [Text10].Visible = True
  8.     [Text8].Visible = True

I'm sure the problem is in the code of combo4 but I don't know how to fix it. Any help would be greatly appreciated and Thanks in advance!

msquared's Avatar
Administrator
 
Join Date: Aug 2006
Location: Dublin, Ireland
Posts: 10,886
#2: Jun 22 '07

re: Another Multiple Combo box Question


Have a look at this tutorial.

Cascading combo/list boxes
Newbie
 
Join Date: Nov 2006
Posts: 25
#3: Jun 22 '07

re: Another Multiple Combo box Question


Yea, I've looked at this and my Combo boxes work fine. it's the results I want in the text boxes after picking from the combo boxes that I'm having a problem with.

Thanks!
msquared's Avatar
Administrator
 
Join Date: Aug 2006
Location: Dublin, Ireland
Posts: 10,886
#4: Jun 22 '07

re: Another Multiple Combo box Question


Quote:

Originally Posted by teric2

Yea, I've looked at this and my Combo boxes work fine. it's the results I want in the text boxes after picking from the combo boxes that I'm having a problem with.

Thanks!

The combo0 After Update does not follow the rules of this tutorial. Have another look at it.
Newbie
 
Join Date: Nov 2006
Posts: 25
#5: Jun 22 '07

re: Another Multiple Combo box Question


I don't think that code will work for me but I could be wrong. Here is the structure of my customer table

RXDC no <-- a unique id number or text string(field is set as text)
customer name
Address1
Address2
City
State
Zip

Each customer may have many locations in different citys each with it's own Unique ID(RXDC no) and record in the table

Combo0's row source is set to a Query that contains the customer name field sorted and set to show unique values so the same customer name doesn't appear over and over again in the combo box.

The code in the tutorial is set to return the unique ID number for the customer name selected. Which, in my case, the name for several locations will only display once.
It's the combination of Combo0(Customer Name) and Combo4(City) that will result in the unique ID(RXDC no) and record I'm looking for to display in my two text boxes.

What I want is to choose a customer name and then a city for that customer and then have the state and unquie ID for that combination display in the text boxes
msquared's Avatar
Administrator
 
Join Date: Aug 2006
Location: Dublin, Ireland
Posts: 10,886
#6: Jun 22 '07

re: Another Multiple Combo box Question


Combo0
Row Source = SELECT DISTINCT [customer name] FROM Customers

Expand|Select|Wrap|Line Numbers
  1. Private Sub Combo0_AfterUpdate()
  2. Dim strRowSource As String
  3.  
  4.     Me!Combo4.Visible = True
  5.     strRowSource = "SELECT City FROM Customers WHERE [company name]='" & Me!Combo0 & "'"
  6.     Me!Combo4.RowSource = strRowSource
  7.     Me!Combo4.Requery
  8.  
  9. End Sub
  10.  
Assuming you have a textbox to hold the value of the RXDC no called txtRXDC

Expand|Select|Wrap|Line Numbers
  1. Private Sub Combo4_AfterUpdate()
  2.  
  3.     Me!txtRXDC = DLookup("[RXDC no]", "Customers", "[customer name]='" & Me!Combo0 & "' AND [City]='"  & Me!Combo4 & "'"
  4.  
  5. End Sub
  6.  
Newbie
 
Join Date: Nov 2006
Posts: 25
#7: Jun 22 '07

re: Another Multiple Combo box Question


This works great mmccarthy. I knew you'd come through for me. You've helped me before.

One more question.
Some of my customer names have an apostrophe in them to show possesion. When I select one of these I get a "Syntax error" in the code for combo4.

Anyway to fix it other than to remove the apostrophes?
msquared's Avatar
Administrator
 
Join Date: Aug 2006
Location: Dublin, Ireland
Posts: 10,886
#8: Jun 22 '07

re: Another Multiple Combo box Question


Quote:

Originally Posted by teric2

This works great mmccarthy. I knew you'd come through for me. You've helped me before.

One more question.
Some of my customer names have an apostrophe in them to show possesion. When I select one of these I get a "Syntax error" in the code for combo4.

Anyway to fix it other than to remove the apostrophes?

Try this

"SELECT City FROM Customers WHERE [company name]=" & """ & Me!Combo0 & """
Newbie
 
Join Date: Nov 2006
Posts: 25
#9: Jun 22 '07

re: Another Multiple Combo box Question


Hmm that results in combo4 being empty.
msquared's Avatar
Administrator
 
Join Date: Aug 2006
Location: Dublin, Ireland
Posts: 10,886
#10: Jun 22 '07

re: Another Multiple Combo box Question


Quote:

Originally Posted by teric2

Hmm that results in combo4 being empty.

I know there's a way of dealing with this, I just can't remember it at the moment.

I'll get back to you
msquared's Avatar
Administrator
 
Join Date: Aug 2006
Location: Dublin, Ireland
Posts: 10,886
#11: Jun 22 '07

re: Another Multiple Combo box Question


Try this ...

"SELECT City FROM Customers WHERE [company name]=""" & Me!Combo0 & """"

If that doesn't work you may need to use this function.

http://www.thescripts.com/forum/thread641552.html
Newbie
 
Join Date: Nov 2006
Posts: 25
#12: Jun 26 '07

re: Another Multiple Combo box Question


That worked except now I get a syntax error (Missing Operator) for this code in the AfterUpdate procedure of the second combo box(Combo4):

Expand|Select|Wrap|Line Numbers
  1. Me!Text8 = DLookup("[RXDC no]", "Customers", "[company name]='" & Me!Combo0 & "' AND [City]='" & Me!Combo4 & "'")
Sorry it took so long to get back to this and thanks again for helping.
msquared's Avatar
Administrator
 
Join Date: Aug 2006
Location: Dublin, Ireland
Posts: 10,886
#13: Jun 26 '07

re: Another Multiple Combo box Question


Try this

Expand|Select|Wrap|Line Numbers
  1. Me!Text8 = DLookup("[RXDC no]", "Customers", "[company name]=""" & Me!Combo0 & """" & " AND [City]='" & Me!Combo4 & "'")
  2.  
Newbie
 
Join Date: Nov 2006
Posts: 25
#14: Jun 27 '07

re: Another Multiple Combo box Question


Afraid not. Still get the same error. Guess I'll have to try the function that you pointed me to unless you have any more ideas.
msquared's Avatar
Administrator
 
Join Date: Aug 2006
Location: Dublin, Ireland
Posts: 10,886
#15: Jun 27 '07

re: Another Multiple Combo box Question


Quote:

Originally Posted by teric2

Afraid not. Still get the same error. Guess I'll have to try the function that you pointed me to unless you have any more ideas.

I'm not sure whats going on but I've tested the code

Me!Text8 = DLookup("[RXDC no]", "Customers", "[company name]=""" & Me!Combo0 & """" & " AND [City]='" & Me!Combo4 & "'")

And it works fine
Newbie
 
Join Date: Nov 2006
Posts: 25
#16: Jun 27 '07

re: Another Multiple Combo box Question


My mistake. I should have looked closer. I copied and pasted your code but, in the mean time, I somehow lost the original SQL from Combo0.

Works great now!

Thanks tons for your time and patience. This is a great place to learn.
msquared's Avatar
Administrator
 
Join Date: Aug 2006
Location: Dublin, Ireland
Posts: 10,886
#17: Jun 27 '07

re: Another Multiple Combo box Question


Quote:

Originally Posted by teric2

My mistake. I should have looked closer. I copied and pasted your code but, in the mean time, I somehow lost the original SQL from Combo0.

Works great now!

Thanks tons for your time and patience. This is a great place to learn.

Not a problem. Glad you got it working.
Reply