User chooses last name from combo box, queries for first name matc

P

Paul (TRX)

This is going back to what I've asked before. Upon somebody's suggestion, I
searched "cascading combo boxes" or something along those lines. I found a
site with code on how to do what I wanted and entered the code correctly, but
all I get is an error message. Here is the code:

Private Sub Lname_AfterUpdate()
On Error Resume Next
Fname.RowSource = "Select tblRoster.Fname " & _
"FROM tblRoster " & _
"WHERE tblRoster.Lname = '" & Lname.Value & "' " & _
"ORDER BY tblRoster.Fname;"
End Sub

I enter this in the "After Update" event in the properties of the Lname
(last name) combo box so that, after the user selects a last name, it should
query the database and pull ONLY the first names that match that last name.
Instead of doing that, it keeps giving me the following error message:

Miscrosoft Office Access can't find the macro 'Fname
The macro (or its macro group) doesn't exist, or the macro is new but hasn't
been saved.
Note that when you enter the macrogroupname.macroname syntax in an argument,
you must specify the name the macro's macro group was last saved under.


I can't understand what I am doing wrong. Can anybody help?

--
Have a nice day!

~Paul

~~~~~~
| |
|c--OD
| _)
| |
|-. |
/ `-# /A
/ /_|..`#.J/
||LJ `m''''''''
ptaylor
 
P

Paul (TRX)

Nevermind. I figured out the problem. I had to add that in Visual Basic, not
right in the event itself. It is working now.

--
Have a nice day!

~Paul

~~~~~~
| |
|c--OD
| _)
| |
|-. |
/ `-# /A
/ /_|..`#.J/
||LJ `m''''''''
ptaylor
 
F

fredg

This is going back to what I've asked before. Upon somebody's suggestion, I
searched "cascading combo boxes" or something along those lines. I found a
site with code on how to do what I wanted and entered the code correctly, but
all I get is an error message. Here is the code:

Private Sub Lname_AfterUpdate()
On Error Resume Next
Fname.RowSource = "Select tblRoster.Fname " & _
"FROM tblRoster " & _
"WHERE tblRoster.Lname = '" & Lname.Value & "' " & _
"ORDER BY tblRoster.Fname;"
End Sub

I enter this in the "After Update" event in the properties of the Lname
(last name) combo box so that, after the user selects a last name, it should
query the database and pull ONLY the first names that match that last name.
Instead of doing that, it keeps giving me the following error message:

Miscrosoft Office Access can't find the macro 'Fname
The macro (or its macro group) doesn't exist, or the macro is new but hasn't
been saved.
Note that when you enter the macrogroupname.macroname syntax in an argument,
you must specify the name the macro's macro group was last saved under.

I can't understand what I am doing wrong. Can anybody help?

I see, from your follow up post, that you figured it out.
However, I would suggest that you change the Where clause a bit.
As written, your code will crash if it runs across a name with an
apostrophe, i.e. O'Leary, O'Connor, etc.

Instead use:

"WHERE tblRoster.Lname = """ & Lname.Value & """" & _
 
P

Paul (TRX)

Thank you. That is good to know. I've made that change.

--
Have a nice day!

~Paul

~~~~~~
| |
|c--OD
| _)
| |
|-. |
/ `-# /A
/ /_|..`#.J/
||LJ `m''''''''
ptaylor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top