Need Help URGENTLY.....

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi all expert here,

I am creating a form in which it contains two LIST BOXES.

The first list boxes will ask the inputter to choose the CLASS. Then after
the inputter choose the CLASS, the second list box will populate another list
box which populate the student name of the CLASS accordingly.

I have already created a query to get the student name, and have set the
record source of my second list box to the QUERY. However, it still doesnt
work.

It seems that i have to create a MACRO to Set Value or what to the first
list box ON EVENT of the first list box such as ON CLICK or what. But i
really got no idea on how Macro works.....

Help here will absolutely save my life... thanks much.....~~
 
Without knowing your tables, I can't give a specific answer, but what you
need to do is put code in the AfterUpdate event of the first listbox to
change the row source for the second listbox to include the selected
value(s) from the first one in its WHERE clause.

http://www.mvps.org/access/forms/frm0028.htm at "The Access Web" is an
example of what I'm talking about, as is
http://support.microsoft.com/?kbid=289670 While both of them are talking
about combo boxes, it's similar for list boxes.
 
Thanks.. but i am stupid in SQL and vbasic... i can provide more details..
can you help me to put on the code....?? million thanks....

my first list box named "classlist"

my query is named "draw student name", and the field that i wanna put on the
listbox 2 in the query named "student name", and the mapping field of the
query is the "classname".

The second list box named "student name".
 
Thanks.. but i am stupid in SQL and vbasic... i can provide more details..
can you help me to put on the code....?? million thanks....

my first list box named "classlist"

my query is named "draw student name", and the field that i wanna put on the
listbox 2 in the query named "student name", and the mapping field of the
query is the "classname".

The second list box named "student name".

It's really best NOT to use blanks in the names of objects - you can
get away with it but it makes your code a bit harder to write.

What you should do is base the [Student Name] listbox on a Query, in
this case [draw student name] - or, as I'd recommend,
[DrawStudentName]. In that query, put

=[Forms]![NameOfYourForm]![Classlist]

on the criteria line under the class ID field. This will set up the
listbox to display only students matching the selected class.

You need only one easy line of VBA. In the Properties of the Classlist
listbox, find the "AfterUpdate" property (on the Events tab); click
the ... icon by it; and select "Code Builder". Access will give you a
Sub and End Sub line for free, just add one more line between them:

Private Sub Classlist_AfterUpdate()
Me![Student Name].Requery
End Sub

This will alert the second listbox that the value in the first listbox
has changed.

John W. Vinson[MVP]
 
Hi.. it works well for only ONCE. If i change the value of the first list
box.. the requery seems doest work. Please advice.

Thanks much.

John Vinson said:
Thanks.. but i am stupid in SQL and vbasic... i can provide more details..
can you help me to put on the code....?? million thanks....

my first list box named "classlist"

my query is named "draw student name", and the field that i wanna put on the
listbox 2 in the query named "student name", and the mapping field of the
query is the "classname".

The second list box named "student name".

It's really best NOT to use blanks in the names of objects - you can
get away with it but it makes your code a bit harder to write.

What you should do is base the [Student Name] listbox on a Query, in
this case [draw student name] - or, as I'd recommend,
[DrawStudentName]. In that query, put

=[Forms]![NameOfYourForm]![Classlist]

on the criteria line under the class ID field. This will set up the
listbox to display only students matching the selected class.

You need only one easy line of VBA. In the Properties of the Classlist
listbox, find the "AfterUpdate" property (on the Events tab); click
the ... icon by it; and select "Code Builder". Access will give you a
Sub and End Sub line for free, just add one more line between them:

Private Sub Classlist_AfterUpdate()
Me![Student Name].Requery
End Sub

This will alert the second listbox that the value in the first listbox
has changed.

John W. Vinson[MVP]
 
Hi John,

I succesfully manage to have something achieved at this stage. HOWEVER,
somehow after i click the first listbox, the content of the second list box
did come out (with the correct result set). Strangely, the SECOND list box
did not show anything. But if i copy and paste the content of the seond list
box, i did have the correct result set.

Please advice.

Thanks much.

kaci said:
Hi.. it works well for only ONCE. If i change the value of the first list
box.. the requery seems doest work. Please advice.

Thanks much.

John Vinson said:
Thanks.. but i am stupid in SQL and vbasic... i can provide more details..
can you help me to put on the code....?? million thanks....

my first list box named "classlist"

my query is named "draw student name", and the field that i wanna put on the
listbox 2 in the query named "student name", and the mapping field of the
query is the "classname".

The second list box named "student name".

It's really best NOT to use blanks in the names of objects - you can
get away with it but it makes your code a bit harder to write.

What you should do is base the [Student Name] listbox on a Query, in
this case [draw student name] - or, as I'd recommend,
[DrawStudentName]. In that query, put

=[Forms]![NameOfYourForm]![Classlist]

on the criteria line under the class ID field. This will set up the
listbox to display only students matching the selected class.

You need only one easy line of VBA. In the Properties of the Classlist
listbox, find the "AfterUpdate" property (on the Events tab); click
the ... icon by it; and select "Code Builder". Access will give you a
Sub and End Sub line for free, just add one more line between them:

Private Sub Classlist_AfterUpdate()
Me![Student Name].Requery
End Sub

This will alert the second listbox that the value in the first listbox
has changed.

John W. Vinson[MVP]
 
Back
Top