Connecting Tech Pros Worldwide Forums | Help | Site Map

need help with cascading combo/list boxes

Newbie
 
Join Date: Aug 2007
Posts: 18
#1: Aug 15 '07
Hey i need help with setting up this on ACCESS 2007
i need step by step

i need a form...
i select a name (drop list)...then gives me more choice (in next drop list) ....then when i select that choice give another list (drop list)..

so for example
i select canada, from list of contries, then i would get list of the provinces and then i choose my province and then i get list of cities

if someone let me know step by step how to do that i would appericiate it.
Rabbit's Avatar
Expert
 
Join Date: Jan 2007
Location: California
Posts: 3,835
#2: Aug 15 '07

re: need help with cascading combo/list boxes


You have posted in the wrong forum, I am moving this post the the appropriate forum.

Please use a clearer title next time. I will change it for you this time.
Rabbit's Avatar
Expert
 
Join Date: Jan 2007
Location: California
Posts: 3,835
#3: Aug 15 '07

re: need help with cascading combo/list boxes


Take a look at the Cascading Combo/List Box Tutorial.
Newbie
 
Join Date: Aug 2007
Posts: 18
#4: Aug 15 '07

re: need help with cascading combo/list boxes


thank you so much you saved my life!!!!! also i didnt know it was called cascading combo box.
Rabbit's Avatar
Expert
 
Join Date: Jan 2007
Location: California
Posts: 3,835
#5: Aug 15 '07

re: need help with cascading combo/list boxes


Quote:

Originally Posted by pouj

thank you so much you saved my life!!!!! also i didnt know it was called cascading combo box.

You don't have to know what it's called but the title should be descriptive of the question.
Newbie
 
Join Date: Aug 2007
Posts: 18
#6: Aug 15 '07

re: need help with cascading combo/list boxes


okay so i read over cascading combo/list boxes tutorial and my projct doesnt work.

i will tell you exactly what i have done...

my first table called tblcontractor..
has 2 field
ID: Automatic
ContractorIDNumber: Number (which gets its data from another table)

my next table called tblcontractorproject
has 3 fields
ID: autonumber
Contractorprojectname: text
contractoridnumber: Number (which gets i data from same table that tblcontracot contractoridnumber gets it data)

then i create a form and then form i drop the the tables in there..and i went to properties and i went to afterupdate and i put in [Event Procedure] and i went to VB editor and i type this in there...
Expand|Select|Wrap|Line Numbers
  1. Private Sub ContractorIDNumber_AfterUpdate()
  2. With Me![ContractorIDNumber]
  3. If IsNull(Me!ContractorIDNumber) Then
  4. .RowSource = ""
  5. Else
  6. .RowSource = "SELECT [Contractorprojectname] " & _
  7. "FROM Tblcontractproject " & _
  8. "WHERE [ID]=" & Me!ContractorIDNumber
  9. End If
  10. Call .Requery
  11. End With
  12. End Sub
  13.  
also keep in mind that i have no data in the tables yet. so if you tell me what i am doing wrong here, i would apperciate it.
Rabbit's Avatar
Expert
 
Join Date: Jan 2007
Location: California
Posts: 3,835
#7: Aug 15 '07

re: need help with cascading combo/list boxes


Quote:

Originally Posted by pouj

okay so i read over cascading combo/list boxes tutorial and my projct doesnt work.

i will tell you exactly what i have done...

my first table called tblcontractor..
has 2 field
ID: Automatic
ContractorIDNumber: Number (which gets its data from another table)

my next table called tblcontractorproject
has 3 fields
ID: autonumber
Contractorprojectname: text
contractoridnumber: Number (which gets i data from same table that tblcontracot contractoridnumber gets it data)

then i create a form and then form i drop the the tables in there..and i went to properties and i went to afterupdate and i put in [Event Procedure] and i went to VB editor and i type this in there...

Private Sub ContractorIDNumber_AfterUpdate()
With Me![ContractorIDNumber]
If IsNull(Me!ContractorIDNumber) Then
.RowSource = ""
Else
.RowSource = "SELECT [Contractorprojectname] " & _
"FROM Tblcontractproject " & _
"WHERE [ID]=" & Me!ContractorIDNumber
End If
Call .Requery
End With
End Sub

also keep in mind that i have no data in the tables yet. so if you tell me what i am doing wrong here, i would apperciate it.

When you're doing a cascading combo box you use more than 1 combo box. You're only using one combo box here. Read the tutorial more closely.

You're also attempting to return records based what looks to be a primary key when you should be using a foreign key.
Newbie
 
Join Date: Aug 2007
Posts: 18
#8: Aug 15 '07

re: need help with cascading combo/list boxes


Quote:

Originally Posted by Rabbit

When you're doing a cascading combo box you use more than 1 combo box. You're only using one combo box here. Read the tutorial more closely.

You're also attempting to return records based what looks to be a primary key when you should be using a foreign key.

how do i use foreign key....and i am using 2 combo box.
Rabbit's Avatar
Expert
 
Join Date: Jan 2007
Location: California
Posts: 3,835
#9: Aug 15 '07

re: need help with cascading combo/list boxes


Quote:

Originally Posted by pouj

how do i use foreign key....and i am using 2 combo box.

But your code is only using one combo box.

You use a foreign key by using the foreign key field's name instead of the primary key field's name.
Newbie
 
Join Date: Aug 2007
Posts: 18
#10: Aug 16 '07

re: need help with cascading combo/list boxes


okay...so now my code looks like this....
Expand|Select|Wrap|Line Numbers
  1. Private Sub cpyname_AfterUpdate()
  2.     With Me![Employee]
  3.         If IsNull(Me!company) Then
  4.             .RowSource = ""
  5.         Else
  6.             .RowSource = "select [empname] " & _
  7.             "from tblemployees " & _
  8.             "where [id] =" & Me!company
  9.         End If
  10.         Call .Requery
  11.         End With
  12. End Sub
  13.  
but i am getting debug on With Me![Employee]...so what i am suppose to do there...and also...like i tried to set up FK but it doesnt work (thats what i am assuming) because in relationship field i just get a line from ID to EID..and can you refresh my head with the steps on how to set up FK keys? or i am doing it right...
Rabbit's Avatar
Expert
 
Join Date: Jan 2007
Location: California
Posts: 3,835
#11: Aug 16 '07

re: need help with cascading combo/list boxes


You're going have to give me the relevant information.

What tables are involved.
What fields are in those tables.
What are the primary keys.
How and on what fields are the tables related.

What are the relevant controls on your form.
What are the properties of those controls, i.e. control source, row source, column widths, columns, bound column, name.

The tutorial provides all of these and how to set up the example. So I can't guide you along any better than was laid out in the tutorial. I'll need to know that information if I'm to figure out where you diverted from the tutorial.
Newbie
 
Join Date: Aug 2007
Posts: 18
#12: Aug 16 '07

re: need help with cascading combo/list boxes


i did exactly step by step of what you did. my whole problem is with

With Me![Employee]
Rabbit's Avatar
Expert
 
Join Date: Jan 2007
Location: California
Posts: 3,835
#13: Aug 16 '07

re: need help with cascading combo/list boxes


Quote:

Originally Posted by pouj

i did exactly step by step of what you did. my whole problem is with

With Me![Employee]

I don't know what's wrong with it, you'll need to tell me what Employee is.
Newbie
 
Join Date: Aug 2007
Posts: 18
#14: Aug 16 '07

re: need help with cascading combo/list boxes


okay i will tell you step by step what i have done

i have 2 tables
one is called
tblcompany
and other is called tblemployee

in tblcompany
i got 2 fields
one is ID which is automatic and primary key
and other one is cpyname

then in tblemployee
i got 3 fields
ID which is automatic number and primary key
empname which is text
and EID which is i did lookup wizard to make relationship with ID from tblcompany (i might no idea how to set up foreign key)

then i created a blank form
and drop the fields cpyname and empname

and i changed them both dropbox.
and i put in all the control source and row source and column count a you stated.

and then i went to after update and i put in event procedure and in visual basic i put in this code

Expand|Select|Wrap|Line Numbers
  1. Private Sub cpyname_AfterUpdate()
  2.     With Me![Employee]
  3.         If IsNull(Me!company) Then
  4.             .RowSource = ""
  5.         Else
  6.             .RowSource = "select [empname] " & _
  7.             "from tblemployees " & _
  8.             "where [id] =" & Me!company
  9.         End If
  10.         Call .Requery
  11.         End With
  12. End Sub
  13.  
so what i am doing wrong and where?

i gaved as much details as i could. so i hope this helps
Rabbit's Avatar
Expert
 
Join Date: Jan 2007
Location: California
Posts: 3,835
#15: Aug 16 '07

re: need help with cascading combo/list boxes


Quote:

Originally Posted by pouj

okay i will tell you step by step what i have done

i have 2 tables
one is called
tblcompany
and other is called tblemployee

in tblcompany
i got 2 fields
one is ID which is automatic and primary key
and other one is cpyname

then in tblemployee
i got 3 fields
ID which is automatic number and primary key
empname which is text
and EID which is i did lookup wizard to make relationship with ID from tblcompany (i might no idea how to set up foreign key)

then i created a blank form
and drop the fields cpyname and empname

and i changed them both dropbox.
and i put in all the control source and row source and column count a you stated.

and then i went to after update and i put in event procedure and in visual basic i put in this code


Private Sub cpyname_AfterUpdate()
With Me![Employee]
If IsNull(Me!company) Then
.RowSource = ""
Else
.RowSource = "select [empname] " & _
"from tblemployees " & _
"where [id] =" & Me!company
End If
Call .Requery
End With
End Sub

so what i am doing wrong and where?

i gaved as much details as i could. so i hope this helps

You're using the wrong fields. The main combo box's, cpyname at the moment, control source should be a key field, in this case ID/EID. The second combo box's control source doesn't have to be a key field but if you are storing this data in a related table then it should also be a key field. In this case tblemployee.ID. The code should make reference to these combo boxes, which is usually the same as the name of the field. Which you didn't do.

I also need to know the values for "and i put in all the control source and row source and column count a you stated"

I also need to know what the form is bound to, if anything, and the fields of that table if different from the two you have described.
Newbie
 
Join Date: Aug 2007
Posts: 18
#16: Aug 16 '07

re: need help with cascading combo/list boxes


i did all that as you said..but once again..is being the same...would it be possble if i send you the file so you look at it?
Rabbit's Avatar
Expert
 
Join Date: Jan 2007
Location: California
Posts: 3,835
#17: Aug 16 '07

re: need help with cascading combo/list boxes


I can't open your file, it says unrecognized database format.

Just answer these two questions and I should be able to fix the problem.

I also need to know the values for "and i put in all the control source and row source and column count a you stated"

I also need to know what the form is bound to, if anything, and the fields of that table if different from the two you have described.
Newbie
 
Join Date: Aug 2007
Posts: 18
#18: Aug 16 '07

re: need help with cascading combo/list boxes


is probaly cause is access 2007

okay
here is the information...
for cpyname
name: cpyname
controlsource: cpyname
colum count: 2
colum width: 1
rowsource: tblcompany
rowsource type: table/query
bound colum: 2

for empname
name: empname
controlsource: empname
colum count: 1
colum width: N/A
rowsource:
rowsource type: table/query
bound colum: 2

i will try sending you the db in access 97-2003 format
Rabbit's Avatar
Expert
 
Join Date: Jan 2007
Location: California
Posts: 3,835
#19: Aug 16 '07

re: need help with cascading combo/list boxes


1) Your form's record source uses a join. Joins are not updateable. As your form is setup now, there's no need for the form at all. The whole purpose of having the 2 lookup tables and cascading combo boxes is to populate the fields of a third table. Not to populate themselves.

2) The settings should be
name: cpyname (This should probably be CompanyID)
controlsource: (Whatever field you want to save this to, a third table, not your lookup tables, that defeats the purpose of cascading combo boxes)
colum count: 2
colum width: 0
rowsource: tblcompany
rowsource type: table/query
bound colum: 1

name: empname (This should probably be EmployeeID)
controlsource: (See Above)
colum count: 2
colum width: 0
rowsource:
rowsource type: table/query
bound colum: 1

3) The Code
Expand|Select|Wrap|Line Numbers
  1. Private Sub cpyname_AfterUpdate()
  2.    With Me![empname]
  3.       If IsNull(Me!cpyname) Then
  4.          .RowSource = ""
  5.       Else
  6.          .RowSource = "select id, [empname] " & _
  7.          "from tblemployees " & _
  8.          "where [id] =" & Me!cpyname
  9.       End If
  10.       Call .Requery
  11.    End With
  12. End Sub
  13.  
Newbie
 
Join Date: Aug 2007
Posts: 18
#20: Aug 16 '07

re: need help with cascading combo/list boxes


hey
i just did all that..but now it doesnt requery.....like when i choose company nothing happens in employee....whats the suggestion?
Rabbit's Avatar
Expert
 
Join Date: Jan 2007
Location: California
Posts: 3,835
#21: Aug 16 '07

re: need help with cascading combo/list boxes


What's the record source of your form. Delete whatever's in the record source property of the form.
Newbie
 
Join Date: Aug 2007
Posts: 18
#22: Aug 17 '07

re: need help with cascading combo/list boxes


i did that..and that didnt do any good! still same thing...it shows nothing in employee list.
Rabbit's Avatar
Expert
 
Join Date: Jan 2007
Location: California
Posts: 3,835
#23: Aug 17 '07

re: need help with cascading combo/list boxes


Delete whatever's in the control sources from both combo boxes.
Newbie
 
Join Date: Aug 2007
Posts: 18
#24: Aug 17 '07

re: need help with cascading combo/list boxes


did that, no work...
Rabbit's Avatar
Expert
 
Join Date: Jan 2007
Location: California
Posts: 3,835
#25: Aug 17 '07

re: need help with cascading combo/list boxes


I don't know what you could be doing wrong, send it to me again. I was able to get it working.
Newbie
 
Join Date: Aug 2007
Posts: 18
#26: Aug 22 '07

re: need help with cascading combo/list boxes


okay i finally got your tutorial to work.
okay but now...this is what i am want to do for school project.

I have to set up this cascadog combo/list boxs
basically
they way you would say it english would be like this

if value in combobox1 is Available (combo box choices are available, on project, vacatio)
then search the table1 for anyone with Available status and list them in combobox.

thats how it should be done....if not possible what is my choice.
Rabbit's Avatar
Expert
 
Join Date: Jan 2007
Location: California
Posts: 3,835
#27: Aug 22 '07

re: need help with cascading combo/list boxes


Quote:

Originally Posted by pouj

okay i finally got your tutorial to work.
okay but now...this is what i am want to do for school project.

I have to set up this cascadog combo/list boxs
basically
they way you would say it english would be like this

if value in combobox1 is Available (combo box choices are available, on project, vacatio)
then search the table1 for anyone with Available status and list them in combobox.

thats how it should be done....if not possible what is my choice.

You can do this with the cascading combo boxes. The first combo box holds the status values. The second combo box's row source is changed accordingly in the after update event of the first combo box. It's no different than a cascading combo box save for the exact syntax you use. But the concept is the same.
Reply