473,683 Members | 3,357 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_After Update()
ComboSurname.Ro wSource = "Select Distinct Sheet1.Surname " & _
"FROM Sheet1 " & _
"WHERE Sheet1.Dept = '" & ComboDept.Value & "' " & _
"ORDER BY Sheet1.Surname; "
End Sub

Private Sub ComboSurname_Af terUpdate()
ComboForename.R owSource = "Select Distinct Sheet1.Forename " & _
"FROM Sheet1 " & _
"WHERE Sheet1.Surname = '" & ComboSurname.Va lue & "' " & _
"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("T estQuery")

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

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

If IsNull(Me.Combo Forename.Value) Then
strForename = " Like '*' "
Else
strForename = "='" & Me.ComboForenam e.Value & "' "
End If

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

If IsNull(Me.Combo Attending.Value ) Then
strAttending = " Like '*' "
Else
strAttending = "='" & Me.ComboAttendi ng.Value & "' "
End If

If IsNull(Me.Combo Training.Value) Then
strTraining = " Like '*' "
Else
strTraining = "='" & Me.ComboTrainin g.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 2083
vi*********@goo glemail.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_After Update()
ComboSurname.Ro wSource = "Select Distinct Sheet1.Surname " & _
"FROM Sheet1 " & _
"WHERE Sheet1.Dept = '" & ComboDept.Value & "' " & _
"ORDER BY Sheet1.Surname; "
End Sub

Private Sub ComboSurname_Af terUpdate()
ComboForename.R owSource = "Select Distinct Sheet1.Forename " & _
"FROM Sheet1 " & _
"WHERE Sheet1.Surname = '" & ComboSurname.Va lue & "' " & _
"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("T estQuery")

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

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

If IsNull(Me.Combo Forename.Value) Then
strForename = " Like '*' "
Else
strForename = "='" & Me.ComboForenam e.Value & "' "
End If

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

If IsNull(Me.Combo Attending.Value ) Then
strAttending = " Like '*' "
Else
strAttending = "='" & Me.ComboAttendi ng.Value & "' "
End If

If IsNull(Me.Combo Training.Value) Then
strTraining = " Like '*' "
Else
strTraining = "='" & Me.ComboTrainin g.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.ComboSurna me
ORDER BY Forename

The Form.ControlNam e 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_After Update()

Me!ComboSurname .Requery
Me!ComboForenam e.Requery

End Sub

Private Sub ComboSurname_Af terUpdate()

Me!ComboForenam e.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:::mgf0 0 <atearthlink <decimal-pointnet
Oakland, CA (USA)

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

iQA/AwUBRKl+b4echKq OuFEgEQJ4LgCgiU 9B868HgrKlHOQDS x/2nhIYztMAnjLO
XnZg0zwK9AKInlk EERsnn2Or
=wjqz
-----END PGP SIGNATURE-----
Jul 3 '06 #2

MGFoster wrote:
vi*********@goo glemail.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_After Update()
ComboSurname.Ro wSource = "Select Distinct Sheet1.Surname " & _
"FROM Sheet1 " & _
"WHERE Sheet1.Dept = '" & ComboDept.Value & "' " & _
"ORDER BY Sheet1.Surname; "
End Sub

Private Sub ComboSurname_Af terUpdate()
ComboForename.R owSource = "Select Distinct Sheet1.Forename " & _
"FROM Sheet1 " & _
"WHERE Sheet1.Surname = '" & ComboSurname.Va lue & "' " & _
"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("T estQuery")

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

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

If IsNull(Me.Combo Forename.Value) Then
strForename = " Like '*' "
Else
strForename = "='" & Me.ComboForenam e.Value & "' "
End If

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

If IsNull(Me.Combo Attending.Value ) Then
strAttending = " Like '*' "
Else
strAttending = "='" & Me.ComboAttendi ng.Value & "' "
End If

If IsNull(Me.Combo Training.Value) Then
strTraining = " Like '*' "
Else
strTraining = "='" & Me.ComboTrainin g.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.ComboSurna me
ORDER BY Forename

The Form.ControlNam e 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_After Update()

Me!ComboSurname .Requery
Me!ComboForenam e.Requery

End Sub

Private Sub ComboSurname_Af terUpdate()

Me!ComboForenam e.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:::mgf0 0 <atearthlink <decimal-pointnet
Oakland, CA (USA)

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

iQA/AwUBRKl+b4echKq OuFEgEQJ4LgCgiU 9B868HgrKlHOQDS x/2nhIYztMAnjLO
XnZg0zwK9AKInlk EERsnn2Or
=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*********@goo glemail.com wrote:
MGFoster wrote:
>>vi*********@g ooglemail.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_After Update()
ComboSurname .RowSource = "Select Distinct Sheet1.Surname " & _
"FROM Sheet1 " & _
"WHERE Sheet1.Dept = '" & ComboDept.Value & "' " & _
"ORDER BY Sheet1.Surname; "
End Sub

Private Sub ComboSurname_Af terUpdate()
ComboForenam e.RowSource = "Select Distinct Sheet1.Forename " & _
"FROM Sheet1 " & _
"WHERE Sheet1.Surname = '" & ComboSurname.Va lue & "' " & _
"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("T estQuery")

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

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

If IsNull(Me.Combo Forename.Value) Then
strForename = " Like '*' "
Else
strForename = "='" & Me.ComboForenam e.Value & "' "
End If

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

If IsNull(Me.Combo Attending.Value ) Then
strAttending = " Like '*' "
Else
strAttending = "='" & Me.ComboAttendi ng.Value & "' "
End If

If IsNull(Me.Combo Training.Value) Then
strTraining = " Like '*' "
Else
strTraining = "='" & Me.ComboTrainin g.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.ComboSurna me
ORDER BY Forename

The Form.ControlNam e 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_After Update()

Me!ComboSurname .Requery
Me!ComboForenam e.Requery

End Sub

Private Sub ComboSurname_Af terUpdate()

Me!ComboForenam e.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
ControlSour ce properties).

After the Department, Surname, Forename have been selected then run the
CommandButt on "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:::mg f00 <atearthlink <decimal-pointnet
Oakland, CA (USA)

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

iQA/AwUBRKl+b4echKq OuFEgEQJ4LgCgiU 9B868HgrKlHOQDS x/2nhIYztMAnjLO
XnZg0zwK9AKIn lkEERsnn2Or
=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:::mgf0 0 <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.com wrote in message
news:Dn******** ********@newsre ad2.news.pas.ea rthlink.net...
vi*********@goo glemail.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_After Update()
ComboSurnam e.RowSource = "Select Distinct Sheet1.Surname " & _
"FROM Sheet1 " & _
"WHERE Sheet1.Dept = '" & ComboDept.Value & "' " & _
"ORDER BY Sheet1.Surname; "
End Sub

Private Sub ComboSurname_Af terUpdate()
ComboForena me.RowSource = "Select Distinct Sheet1.Forename " & _
"FROM Sheet1 " & _
"WHERE Sheet1.Surname = '" & ComboSurname.Va lue & "' " & _
"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("T estQuery")

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

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

If IsNull(Me.Combo Forename.Value) Then
strForename = " Like '*' "
Else
strForename = "='" & Me.ComboForenam e.Value & "' "
End If

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

If IsNull(Me.Combo Attending.Value ) Then
strAttending = " Like '*' "
Else
strAttending = "='" & Me.ComboAttendi ng.Value & "' "
End If

If IsNull(Me.Combo Training.Value) Then
strTraining = " Like '*' "
Else
strTraining = "='" & Me.ComboTrainin g.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.ComboSurna me
ORDER BY Forename

The Form.ControlNam e 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_After Update()

Me!ComboSurname .Requery
Me!ComboForenam e.Requery

End Sub

Private Sub ComboSurname_Af terUpdate()

Me!ComboForenam e.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
ControlSourc e properties).

After the Department, Surname, Forename have been selected then run the
CommandButto n "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:::m gf00 <atearthlink <decimal-pointnet
Oakland, CA (USA)

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

iQA/AwUBRKl+b4echKq OuFEgEQJ4LgCgiU 9B868HgrKlHOQDS x/2nhIYztMAnjLO
XnZg0zwK9AKI nlkEERsnn2Or
=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:::mgf0 0 <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
2012
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 of the browser window - Will have fairly heavy Safari and Firefox views (~25%) Finding a cascading menu is easy, I trip over about half a dozen of those a week. The problem is when you maximize on a big screen in
2
9737
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
1162
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 javascript, I would like to access these items serverside on a postback, is this possible? At the moment when posting back the cascading dropdown the items collection contains only one item, the item selected.
2
2520
by: malhar | last post by:
hi friends....i want a help for cascading my drop down lists....
1
1207
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 and the addeventListener but that is all I really know. Thanks in advance, Terry
3
1956
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 criteria expression" error that I can not seem to figure out. I hope someone can help... The background is that I have two drop down boxes on a form called: cboPolicyName cboPolicyNumber On the rowsource for the cboPolicyName I have it pointing to my table:
3
3980
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 Division is selected, the appropriate Segment list will 'display in the drop down list of CboSegment With Me! If IsNull(Me!cboDivision) Then
18
2110
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 figured out the right code. That being said, I have a new challenge which I'm not sure how to go about. Here is my situation: I presently have 2 combo boxes (cboBuilding, cboRoom) and which are properly cascading. That's great, but now I want to be able to pull the RoomDescription for the room that...
3
1474
by: Outback | last post by:
Hi. Windows XP + Access 2002. I have three tables. tblMakes ======= MakeKey (PK) Make tblModels
0
8568
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8504
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8922
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8751
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7581
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5789
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2934
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2195
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
1921
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.