472,352 Members | 1,543 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,352 software developers and data experts.

Cascading lists problem

Hi there,
I am building a database that requires cascading lists on a form.
I currently have (I may be adding more later) 3 combo boxes on my form
- Department, Surname and Forename.
The user chooses the department they want and then the corresponding
surnames from that department can be chosen from the Surname box and
then the Forename depending on which Surname they chose.
I then have a command button which produces the results of the
selection in a query (basically running a query 'on the fly').
The database is a training database so it is likely that there will be
more than 1 record of training for each member of staff.
The following is the code I have used for the combo boxes:

Private Sub ComboDept_AfterUpdate()
ComboSurname.RowSource = "Select Distinct Sheet1.Surname " & _
"FROM Sheet1 " & _
"WHERE Sheet1.Dept = '" & ComboDept.Value & "' " & _
"ORDER BY Sheet1.Surname;"
End Sub

Private Sub ComboSurname_AfterUpdate()
ComboForename.RowSource = "Select Distinct Sheet1.Forename " & _
"FROM Sheet1 " & _
"WHERE Sheet1.Surname = '" & ComboSurname.Value & "' " & _
"ORDER BY Sheet1.Forename;"
End Sub

'Sheet 1' is the table it reads from.

And this is the code in my command button:

Private Sub Command5_Click()
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim strSQL As String
Dim strDept As String
Dim strSurname As String
Dim strForename As String
Dim strTeam As String
Dim strAttending As String
Dim strTraining As String
Set db = CurrentDb
Set qdf = db.QueryDefs("TestQuery")

If IsNull(Me.ComboDept.Value) Then
strDept = " Like '*' "
Else
strDept = "='" & Me.ComboDept.Value & "' "
End If

If IsNull(Me.ComboSurname.Value) Then
strSurname = " Like '*' "
Else
strSurname = "='" & Me.ComboSurname.Value & "' "
End If

If IsNull(Me.ComboForename.Value) Then
strForename = " Like '*' "
Else
strForename = "='" & Me.ComboForename.Value & "' "
End If

If IsNull(Me.ComboTeam.Value) Then
strTeam = " Like '*' "
Else
strTeam = "='" & Me.ComboTeam.Value & "' "
End If

If IsNull(Me.ComboAttending.Value) Then
strAttending = " Like '*' "
Else
strAttending = "='" & Me.ComboAttending.Value & "' "
End If

If IsNull(Me.ComboTraining.Value) Then
strTraining = " Like '*' "
Else
strTraining = "='" & Me.ComboTraining.Value & "' "
End If

strSQL = "SELECT StaffTeamQuery.* " & _
"FROM StaffTeamQuery " & _
"WHERE StaffTeamQuery.Dept" & strDept & _
"AND StaffTeamQuery.Surname" & strSurname & _
"AND StaffTeamQuery.Forename" & strForename & _
"AND StaffTeamQuery.Team" & strTeam & _
"AND StaffTeamQuery.Attending" & strAttending & _
"AND StaffTeamQuery.Training" & strTraining
qdf.SQL = strSQL
DoCmd.OpenQuery "TestQuery"
Set qdf = Nothing
Set db = Nothing

End Sub

The problem I have is, for certain members of staff, where there are 2
entries, it'll only display 1 entry and not the other and for some
members of staff it will not display any information at all.
Also, sometimes, if a persons Surname and Forename are left in the
combo boxes from the previous open of the form, they're department is
changed automatically in my table when a department is selected when
the form is re-opened and a new search started.

Sorry for the long winded post but I wanted to make it as detailed as
possible as I am exhausted of ideas!
Many Thanks!

R.

Jul 3 '06 #1
6 1981
vi*********@googlemail.com wrote:
Hi there,
I am building a database that requires cascading lists on a form.
I currently have (I may be adding more later) 3 combo boxes on my form
- Department, Surname and Forename.
The user chooses the department they want and then the corresponding
surnames from that department can be chosen from the Surname box and
then the Forename depending on which Surname they chose.
I then have a command button which produces the results of the
selection in a query (basically running a query 'on the fly').
The database is a training database so it is likely that there will be
more than 1 record of training for each member of staff.
The following is the code I have used for the combo boxes:

Private Sub ComboDept_AfterUpdate()
ComboSurname.RowSource = "Select Distinct Sheet1.Surname " & _
"FROM Sheet1 " & _
"WHERE Sheet1.Dept = '" & ComboDept.Value & "' " & _
"ORDER BY Sheet1.Surname;"
End Sub

Private Sub ComboSurname_AfterUpdate()
ComboForename.RowSource = "Select Distinct Sheet1.Forename " & _
"FROM Sheet1 " & _
"WHERE Sheet1.Surname = '" & ComboSurname.Value & "' " & _
"ORDER BY Sheet1.Forename;"
End Sub

'Sheet 1' is the table it reads from.

And this is the code in my command button:

Private Sub Command5_Click()
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim strSQL As String
Dim strDept As String
Dim strSurname As String
Dim strForename As String
Dim strTeam As String
Dim strAttending As String
Dim strTraining As String
Set db = CurrentDb
Set qdf = db.QueryDefs("TestQuery")

If IsNull(Me.ComboDept.Value) Then
strDept = " Like '*' "
Else
strDept = "='" & Me.ComboDept.Value & "' "
End If

If IsNull(Me.ComboSurname.Value) Then
strSurname = " Like '*' "
Else
strSurname = "='" & Me.ComboSurname.Value & "' "
End If

If IsNull(Me.ComboForename.Value) Then
strForename = " Like '*' "
Else
strForename = "='" & Me.ComboForename.Value & "' "
End If

If IsNull(Me.ComboTeam.Value) Then
strTeam = " Like '*' "
Else
strTeam = "='" & Me.ComboTeam.Value & "' "
End If

If IsNull(Me.ComboAttending.Value) Then
strAttending = " Like '*' "
Else
strAttending = "='" & Me.ComboAttending.Value & "' "
End If

If IsNull(Me.ComboTraining.Value) Then
strTraining = " Like '*' "
Else
strTraining = "='" & Me.ComboTraining.Value & "' "
End If

strSQL = "SELECT StaffTeamQuery.* " & _
"FROM StaffTeamQuery " & _
"WHERE StaffTeamQuery.Dept" & strDept & _
"AND StaffTeamQuery.Surname" & strSurname & _
"AND StaffTeamQuery.Forename" & strForename & _
"AND StaffTeamQuery.Team" & strTeam & _
"AND StaffTeamQuery.Attending" & strAttending & _
"AND StaffTeamQuery.Training" & strTraining
qdf.SQL = strSQL
DoCmd.OpenQuery "TestQuery"
Set qdf = Nothing
Set db = Nothing

End Sub

The problem I have is, for certain members of staff, where there are 2
entries, it'll only display 1 entry and not the other and for some
members of staff it will not display any information at all.
Also, sometimes, if a persons Surname and Forename are left in the
combo boxes from the previous open of the form, they're department is
changed automatically in my table when a department is selected when
the form is re-opened and a new search started.

Sorry for the long winded post but I wanted to make it as detailed as
possible as I am exhausted of ideas!
Many Thanks!

R.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

You're doing too much. You can reduce the amount of VBA code like this:

Set the RowSource property of the ComboSurname to this (all one line):

SELECT Distinct Surname
FROM Sheet1
WHERE Dept = Form.ComboDept
ORDER BY Surname

Set the RowSource property of the ComboForename to this (all on line):

SELECT Distinct Forename
FROM Sheet1
WHERE Surname = Form.ComboSurname
ORDER BY Forename

The Form.ControlName allows the RowSource query to read the named
control on the same form as the ComboBox.

Then all you need in the ComboBoxes AfterUpdate events is a Requery:

Private Sub ComboDept_AfterUpdate()

Me!ComboSurname.Requery
Me!ComboForename.Requery

End Sub

Private Sub ComboSurname_AfterUpdate()

Me!ComboForename.Requery

End Sub

Since you are using these ComboBoxes as search criteria you should not
bind them to a query or table (IOW, don't put anything in their
ControlSource properties).

After the Department, Surname, Forename have been selected then run the
CommandButton "Command5" click event. BTW, you really have to change
the name of that CommandButton to something more descriptive - it will
make your future maintenance work a lot easier.

You can reduce the If...Then statements to something like the following,
which will allow the users to use wildcard characters.

strSurname = " LIKE '*" & Me!ComboSurname & "*' "

Now a user can enter Johns?n as the surname and get:

Johnson
Johnsen
... etc. ...

--
MGFoster:::mgf00 <atearthlink <decimal-pointnet
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBRKl+b4echKqOuFEgEQJ4LgCgiU9B868HgrKlHOQDSx/2nhIYztMAnjLO
XnZg0zwK9AKInlkEERsnn2Or
=wjqz
-----END PGP SIGNATURE-----
Jul 3 '06 #2

MGFoster wrote:
vi*********@googlemail.com wrote:
Hi there,
I am building a database that requires cascading lists on a form.
I currently have (I may be adding more later) 3 combo boxes on my form
- Department, Surname and Forename.
The user chooses the department they want and then the corresponding
surnames from that department can be chosen from the Surname box and
then the Forename depending on which Surname they chose.
I then have a command button which produces the results of the
selection in a query (basically running a query 'on the fly').
The database is a training database so it is likely that there will be
more than 1 record of training for each member of staff.
The following is the code I have used for the combo boxes:

Private Sub ComboDept_AfterUpdate()
ComboSurname.RowSource = "Select Distinct Sheet1.Surname " & _
"FROM Sheet1 " & _
"WHERE Sheet1.Dept = '" & ComboDept.Value & "' " & _
"ORDER BY Sheet1.Surname;"
End Sub

Private Sub ComboSurname_AfterUpdate()
ComboForename.RowSource = "Select Distinct Sheet1.Forename " & _
"FROM Sheet1 " & _
"WHERE Sheet1.Surname = '" & ComboSurname.Value & "' " & _
"ORDER BY Sheet1.Forename;"
End Sub

'Sheet 1' is the table it reads from.

And this is the code in my command button:

Private Sub Command5_Click()
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim strSQL As String
Dim strDept As String
Dim strSurname As String
Dim strForename As String
Dim strTeam As String
Dim strAttending As String
Dim strTraining As String
Set db = CurrentDb
Set qdf = db.QueryDefs("TestQuery")

If IsNull(Me.ComboDept.Value) Then
strDept = " Like '*' "
Else
strDept = "='" & Me.ComboDept.Value & "' "
End If

If IsNull(Me.ComboSurname.Value) Then
strSurname = " Like '*' "
Else
strSurname = "='" & Me.ComboSurname.Value & "' "
End If

If IsNull(Me.ComboForename.Value) Then
strForename = " Like '*' "
Else
strForename = "='" & Me.ComboForename.Value & "' "
End If

If IsNull(Me.ComboTeam.Value) Then
strTeam = " Like '*' "
Else
strTeam = "='" & Me.ComboTeam.Value & "' "
End If

If IsNull(Me.ComboAttending.Value) Then
strAttending = " Like '*' "
Else
strAttending = "='" & Me.ComboAttending.Value & "' "
End If

If IsNull(Me.ComboTraining.Value) Then
strTraining = " Like '*' "
Else
strTraining = "='" & Me.ComboTraining.Value & "' "
End If

strSQL = "SELECT StaffTeamQuery.* " & _
"FROM StaffTeamQuery " & _
"WHERE StaffTeamQuery.Dept" & strDept & _
"AND StaffTeamQuery.Surname" & strSurname & _
"AND StaffTeamQuery.Forename" & strForename & _
"AND StaffTeamQuery.Team" & strTeam & _
"AND StaffTeamQuery.Attending" & strAttending & _
"AND StaffTeamQuery.Training" & strTraining
qdf.SQL = strSQL
DoCmd.OpenQuery "TestQuery"
Set qdf = Nothing
Set db = Nothing

End Sub

The problem I have is, for certain members of staff, where there are 2
entries, it'll only display 1 entry and not the other and for some
members of staff it will not display any information at all.
Also, sometimes, if a persons Surname and Forename are left in the
combo boxes from the previous open of the form, they're department is
changed automatically in my table when a department is selected when
the form is re-opened and a new search started.

Sorry for the long winded post but I wanted to make it as detailed as
possible as I am exhausted of ideas!
Many Thanks!

R.

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

You're doing too much. You can reduce the amount of VBA code like this:

Set the RowSource property of the ComboSurname to this (all one line):

SELECT Distinct Surname
FROM Sheet1
WHERE Dept = Form.ComboDept
ORDER BY Surname

Set the RowSource property of the ComboForename to this (all on line):

SELECT Distinct Forename
FROM Sheet1
WHERE Surname = Form.ComboSurname
ORDER BY Forename

The Form.ControlName allows the RowSource query to read the named
control on the same form as the ComboBox.

Then all you need in the ComboBoxes AfterUpdate events is a Requery:

Private Sub ComboDept_AfterUpdate()

Me!ComboSurname.Requery
Me!ComboForename.Requery

End Sub

Private Sub ComboSurname_AfterUpdate()

Me!ComboForename.Requery

End Sub

Since you are using these ComboBoxes as search criteria you should not
bind them to a query or table (IOW, don't put anything in their
ControlSource properties).

After the Department, Surname, Forename have been selected then run the
CommandButton "Command5" click event. BTW, you really have to change
the name of that CommandButton to something more descriptive - it will
make your future maintenance work a lot easier.

You can reduce the If...Then statements to something like the following,
which will allow the users to use wildcard characters.

strSurname = " LIKE '*" & Me!ComboSurname & "*' "

Now a user can enter Johns?n as the surname and get:

Johnson
Johnsen
... etc. ...

--
MGFoster:::mgf00 <atearthlink <decimal-pointnet
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBRKl+b4echKqOuFEgEQJ4LgCgiU9B868HgrKlHOQDSx/2nhIYztMAnjLO
XnZg0zwK9AKInlkEERsnn2Or
=wjqz
-----END PGP SIGNATURE-----
Hi and thanks for your reply,
I have gone through your reply and edited my database as you suggested
but now, when I choose an option in ComboDept, I get no options in the
Surname text box at all. Do you know why this would be? I've tried a
couple of things myself but they don't seem to work...
Thanks again!

R.

Jul 4 '06 #3
vi*********@googlemail.com wrote:
MGFoster wrote:
>>vi*********@googlemail.com wrote:
>>>Hi there,
I am building a database that requires cascading lists on a form.
I currently have (I may be adding more later) 3 combo boxes on my form
- Department, Surname and Forename.
The user chooses the department they want and then the corresponding
surnames from that department can be chosen from the Surname box and
then the Forename depending on which Surname they chose.
I then have a command button which produces the results of the
selection in a query (basically running a query 'on the fly').
The database is a training database so it is likely that there will be
more than 1 record of training for each member of staff.
The following is the code I have used for the combo boxes:

Private Sub ComboDept_AfterUpdate()
ComboSurname.RowSource = "Select Distinct Sheet1.Surname " & _
"FROM Sheet1 " & _
"WHERE Sheet1.Dept = '" & ComboDept.Value & "' " & _
"ORDER BY Sheet1.Surname;"
End Sub

Private Sub ComboSurname_AfterUpdate()
ComboForename.RowSource = "Select Distinct Sheet1.Forename " & _
"FROM Sheet1 " & _
"WHERE Sheet1.Surname = '" & ComboSurname.Value & "' " & _
"ORDER BY Sheet1.Forename;"
End Sub

'Sheet 1' is the table it reads from.

And this is the code in my command button:

Private Sub Command5_Click()
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim strSQL As String
Dim strDept As String
Dim strSurname As String
Dim strForename As String
Dim strTeam As String
Dim strAttending As String
Dim strTraining As String
Set db = CurrentDb
Set qdf = db.QueryDefs("TestQuery")

If IsNull(Me.ComboDept.Value) Then
strDept = " Like '*' "
Else
strDept = "='" & Me.ComboDept.Value & "' "
End If

If IsNull(Me.ComboSurname.Value) Then
strSurname = " Like '*' "
Else
strSurname = "='" & Me.ComboSurname.Value & "' "
End If

If IsNull(Me.ComboForename.Value) Then
strForename = " Like '*' "
Else
strForename = "='" & Me.ComboForename.Value & "' "
End If

If IsNull(Me.ComboTeam.Value) Then
strTeam = " Like '*' "
Else
strTeam = "='" & Me.ComboTeam.Value & "' "
End If

If IsNull(Me.ComboAttending.Value) Then
strAttending = " Like '*' "
Else
strAttending = "='" & Me.ComboAttending.Value & "' "
End If

If IsNull(Me.ComboTraining.Value) Then
strTraining = " Like '*' "
Else
strTraining = "='" & Me.ComboTraining.Value & "' "
End If

strSQL = "SELECT StaffTeamQuery.* " & _
"FROM StaffTeamQuery " & _
"WHERE StaffTeamQuery.Dept" & strDept & _
"AND StaffTeamQuery.Surname" & strSurname & _
"AND StaffTeamQuery.Forename" & strForename & _
"AND StaffTeamQuery.Team" & strTeam & _
"AND StaffTeamQuery.Attending" & strAttending & _
"AND StaffTeamQuery.Training" & strTraining
qdf.SQL = strSQL
DoCmd.OpenQuery "TestQuery"
Set qdf = Nothing
Set db = Nothing

End Sub

The problem I have is, for certain members of staff, where there are 2
entries, it'll only display 1 entry and not the other and for some
members of staff it will not display any information at all.
Also, sometimes, if a persons Surname and Forename are left in the
combo boxes from the previous open of the form, they're department is
changed automatically in my table when a department is selected when
the form is re-opened and a new search started.

Sorry for the long winded post but I wanted to make it as detailed as
possible as I am exhausted of ideas!
Many Thanks!

R.

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

You're doing too much. You can reduce the amount of VBA code like this:

Set the RowSource property of the ComboSurname to this (all one line):

SELECT Distinct Surname
FROM Sheet1
WHERE Dept = Form.ComboDept
ORDER BY Surname

Set the RowSource property of the ComboForename to this (all on line):

SELECT Distinct Forename
FROM Sheet1
WHERE Surname = Form.ComboSurname
ORDER BY Forename

The Form.ControlName allows the RowSource query to read the named
control on the same form as the ComboBox.

Then all you need in the ComboBoxes AfterUpdate events is a Requery:

Private Sub ComboDept_AfterUpdate()

Me!ComboSurname.Requery
Me!ComboForename.Requery

End Sub

Private Sub ComboSurname_AfterUpdate()

Me!ComboForename.Requery

End Sub

Since you are using these ComboBoxes as search criteria you should not
bind them to a query or table (IOW, don't put anything in their
ControlSource properties).

After the Department, Surname, Forename have been selected then run the
CommandButton "Command5" click event. BTW, you really have to change
the name of that CommandButton to something more descriptive - it will
make your future maintenance work a lot easier.

You can reduce the If...Then statements to something like the following,
which will allow the users to use wildcard characters.

strSurname = " LIKE '*" & Me!ComboSurname & "*' "

Now a user can enter Johns?n as the surname and get:

Johnson
Johnsen
... etc. ...

--
MGFoster:::mgf00 <atearthlink <decimal-pointnet
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBRKl+b4echKqOuFEgEQJ4LgCgiU9B868HgrKlHOQDSx/2nhIYztMAnjLO
XnZg0zwK9AKInlkEERsnn2Or
=wjqz
-----END PGP SIGNATURE-----


Hi and thanks for your reply,
I have gone through your reply and edited my database as you suggested
but now, when I choose an option in ComboDept, I get no options in the
Surname text box at all. Do you know why this would be? I've tried a
couple of things myself but they don't seem to work...
Thanks again!

R.
It works for me. Can you show me the SQL string for each ComboBox?
Have you remembered to add the Requery to the dependent ComboBox in the
main combo's AfterUpdate event?
--
MGFoster:::mgf00 <atearthlink <decimal-pointnet
Oakland, CA (USA)
Jul 4 '06 #4
Can one or both of you delete some of the past conversation from your reply?
My finger's sore from all the scrolling I have to do to get to the latest.
If you are going to quote every post in every post, at least post the newest
on top. Thanks.

Larry
"MGFoster" <me@privacy.comwrote in message
news:Dn****************@newsread2.news.pas.earthli nk.net...
vi*********@googlemail.com wrote:
>MGFoster wrote:
>>>vi*********@googlemail.com wrote:

Hi there,
I am building a database that requires cascading lists on a form.
I currently have (I may be adding more later) 3 combo boxes on my form
- Department, Surname and Forename.
The user chooses the department they want and then the corresponding
surnames from that department can be chosen from the Surname box and
then the Forename depending on which Surname they chose.
I then have a command button which produces the results of the
selection in a query (basically running a query 'on the fly').
The database is a training database so it is likely that there will be
more than 1 record of training for each member of staff.
The following is the code I have used for the combo boxes:

Private Sub ComboDept_AfterUpdate()
ComboSurname.RowSource = "Select Distinct Sheet1.Surname " & _
"FROM Sheet1 " & _
"WHERE Sheet1.Dept = '" & ComboDept.Value & "' " & _
"ORDER BY Sheet1.Surname;"
End Sub

Private Sub ComboSurname_AfterUpdate()
ComboForename.RowSource = "Select Distinct Sheet1.Forename " & _
"FROM Sheet1 " & _
"WHERE Sheet1.Surname = '" & ComboSurname.Value & "' " & _
"ORDER BY Sheet1.Forename;"
End Sub

'Sheet 1' is the table it reads from.

And this is the code in my command button:

Private Sub Command5_Click()
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim strSQL As String
Dim strDept As String
Dim strSurname As String
Dim strForename As String
Dim strTeam As String
Dim strAttending As String
Dim strTraining As String
Set db = CurrentDb
Set qdf = db.QueryDefs("TestQuery")

If IsNull(Me.ComboDept.Value) Then
strDept = " Like '*' "
Else
strDept = "='" & Me.ComboDept.Value & "' "
End If

If IsNull(Me.ComboSurname.Value) Then
strSurname = " Like '*' "
Else
strSurname = "='" & Me.ComboSurname.Value & "' "
End If

If IsNull(Me.ComboForename.Value) Then
strForename = " Like '*' "
Else
strForename = "='" & Me.ComboForename.Value & "' "
End If

If IsNull(Me.ComboTeam.Value) Then
strTeam = " Like '*' "
Else
strTeam = "='" & Me.ComboTeam.Value & "' "
End If

If IsNull(Me.ComboAttending.Value) Then
strAttending = " Like '*' "
Else
strAttending = "='" & Me.ComboAttending.Value & "' "
End If

If IsNull(Me.ComboTraining.Value) Then
strTraining = " Like '*' "
Else
strTraining = "='" & Me.ComboTraining.Value & "' "
End If

strSQL = "SELECT StaffTeamQuery.* " & _
"FROM StaffTeamQuery " & _
"WHERE StaffTeamQuery.Dept" & strDept & _
"AND StaffTeamQuery.Surname" & strSurname & _
"AND StaffTeamQuery.Forename" & strForename & _
"AND StaffTeamQuery.Team" & strTeam & _
"AND StaffTeamQuery.Attending" & strAttending & _
"AND StaffTeamQuery.Training" & strTraining
qdf.SQL = strSQL
DoCmd.OpenQuery "TestQuery"
Set qdf = Nothing
Set db = Nothing

End Sub

The problem I have is, for certain members of staff, where there are 2
entries, it'll only display 1 entry and not the other and for some
members of staff it will not display any information at all.
Also, sometimes, if a persons Surname and Forename are left in the
combo boxes from the previous open of the form, they're department is
changed automatically in my table when a department is selected when
the form is re-opened and a new search started.

Sorry for the long winded post but I wanted to make it as detailed as
possible as I am exhausted of ideas!
Many Thanks!

R.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

You're doing too much. You can reduce the amount of VBA code like this:

Set the RowSource property of the ComboSurname to this (all one line):

SELECT Distinct Surname
FROM Sheet1
WHERE Dept = Form.ComboDept
ORDER BY Surname

Set the RowSource property of the ComboForename to this (all on line):

SELECT Distinct Forename
FROM Sheet1
WHERE Surname = Form.ComboSurname
ORDER BY Forename

The Form.ControlName allows the RowSource query to read the named
control on the same form as the ComboBox.

Then all you need in the ComboBoxes AfterUpdate events is a Requery:

Private Sub ComboDept_AfterUpdate()

Me!ComboSurname.Requery
Me!ComboForename.Requery

End Sub

Private Sub ComboSurname_AfterUpdate()

Me!ComboForename.Requery

End Sub

Since you are using these ComboBoxes as search criteria you should not
bind them to a query or table (IOW, don't put anything in their
ControlSource properties).

After the Department, Surname, Forename have been selected then run the
CommandButton "Command5" click event. BTW, you really have to change
the name of that CommandButton to something more descriptive - it will
make your future maintenance work a lot easier.

You can reduce the If...Then statements to something like the following,
which will allow the users to use wildcard characters.

strSurname = " LIKE '*" & Me!ComboSurname & "*' "

Now a user can enter Johns?n as the surname and get:

Johnson
Johnsen
... etc. ...

--
MGFoster:::mgf00 <atearthlink <decimal-pointnet
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBRKl+b4echKqOuFEgEQJ4LgCgiU9B868HgrKlHOQDSx/2nhIYztMAnjLO
XnZg0zwK9AKInlkEERsnn2Or
=wjqz
-----END PGP SIGNATURE-----


Hi and thanks for your reply,
I have gone through your reply and edited my database as you suggested
but now, when I choose an option in ComboDept, I get no options in the
Surname text box at all. Do you know why this would be? I've tried a
couple of things myself but they don't seem to work...
Thanks again!

R.

It works for me. Can you show me the SQL string for each ComboBox? Have
you remembered to add the Requery to the dependent ComboBox in the main
combo's AfterUpdate event?
--
MGFoster:::mgf00 <atearthlink <decimal-pointnet
Oakland, CA (USA)

Jul 4 '06 #5
try double checking the column widths and number of columns for the combo
boxes
---
>
Hi and thanks for your reply,
I have gone through your reply and edited my database as you suggested
but now, when I choose an option in ComboDept, I get no options in the
Surname text box at all. Do you know why this would be? I've tried a
couple of things myself but they don't seem to work...
Thanks again!

R.

Jul 4 '06 #6
Hi guys,
Thanks for all your replies.
I've just managed to sort it as I was logging on...
I'd left the 'row/source type' row blank. Simply changed it to
table/query and it worked!
Stupid mistake I know!
Thanks again for all your help (especially MGFoster).
Cheers,

R.

John Welch (remove remove) wrote:
try double checking the column widths and number of columns for the combo
boxes
---

Hi and thanks for your reply,
I have gone through your reply and edited my database as you suggested
but now, when I choose an option in ComboDept, I get no options in the
Surname text box at all. Do you know why this would be? I've tried a
couple of things myself but they don't seem to work...
Thanks again!

R.
Jul 5 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: JMosey | last post by:
Not sure if this has been covered ( a google search came up pretty bare). I have a site that: - has multi-level cascading menus - floats center...
2
by: Sam | last post by:
A) Destination Table with 4 Fields. 1) Last Name 2) First Name 3) State 4) Zip Code. B) Look up table State/Zip Code with 2 Fields
0
by: robert | last post by:
I am using the new beta 2 ajax control toolkit. When using the cascading drop-down obviously the items in the lists are generated through...
2
by: malhar | last post by:
hi friends....i want a help for cascading my drop down lists....
1
by: tgmurray | last post by:
I looking for advice, guidelines in creating a vertical cascading menu with javascript and css. It seems that I should be using unordered lists...
3
kcdoell
by: kcdoell | last post by:
Hello: I have been struggling with building a cascading list on a form that I created. My problem is that I am getting a "Datatype Mismatch in...
3
kcdoell
by: kcdoell | last post by:
I have 5 cascading combo boxes on a form. Below is a sample of my vb in the first combo box: Private Sub CboDivision_AfterUpdate() 'When the...
18
by: LosLobo | last post by:
Greetings all. I know that cascading lists are a common problem and in truth I my initial post here was to request help with my own, but then I...
3
by: Outback | last post by:
Hi. Windows XP + Access 2002. I have three tables. tblMakes ======= MakeKey (PK) Make tblModels
1
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand....
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.