By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,773 Members | 2,307 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,773 IT Pros & Developers. It's quick & easy.

Action based on a selection in a list box?

P: 41
Is it possible to perform a VBA action based on the selection in a list box?

I have a table with one column as the "answer" text, and another as the record to go to if this particular answer is selected.

What I need is some visual basic to read which item i have selected and then, based on this selection either goto a selected record (based on the value in the column next to the aswer column) or, based on a different column, close the database.

Jan 10 '08 #1
Share this Question
Share on Google+
6 Replies

Expert Mod 10K+
P: 12,356
Yes, you can use the After Update or On Change events of the list box.
Jan 10 '08 #2

P: 45
You mean like this:

Private Sub Combo60_AfterUpdate()
'Find the record that matches the control.
Me.RecordsetClone.FindFirst "[Standard] = '" & Me![Combo60] & "'"
Me.Bookmark = Me.RecordsetClone.Bookmark
End Sub

Here I move to a particular record based on a selection in a combo box. Works the same with list boxes.

This part of the code is where you specify the specific record you want.

"[Standard] = '" & Me![Combo60] & "'"

You can also base your selection on information you can't see. Example say you want to show a specific company record and your company table is based on Client ID (because company names can repeat) you could setup your combo box to show company name and rep but select (bound column) the Client ID so that you can run your selection to the correct record.
Jan 10 '08 #3

P: 41
Thanks for the reply.

I dont quite get what "Standard" is. I assume that:

Combo60 is the list box name
Me.Bookmark is where the result of the check is sent to.

cant figure out what the standard is tho.
Jan 11 '08 #4

P: 41
Just to clarify what im after (not sure I was clear with the initial request)

I have a table with several columns, (lets say a,b,c and d)
column a is an autonumber
column b is text containing an answer
column c is a value for the record to goto is this answer is selected
column d is a yes/no for whether this answer will end the questionnaire or not.

on my form I have a list box (call it list1). this box displays only column b from the answer table.

what i want is for some vba that checks which answer the user has highlighted and then check to see whether the associated column in the answer table d is a no, if its a no then go to record c. if d is yes then end the questionnaire.

Ive had a think about it and i can capture the unique autonumber in column a. This means i can identify which record in the answer table i need to interogate for information.

How would I go about checking column c and d in the answer table based on the value i have for the list box selection?

The current form is not based on the answer table (its based on a question table)

thanks again
Jan 11 '08 #5

P: 45
[Standard] is the name of the column that is being searched for the value you selected in the combo60 pull down. In my example I am searching the record source of the form to move the form to the correct record.

Your additional comments only make the question more confusing. You indicate column a, b. c, d then table d and finally record c and d.

I can't help if I can't follow the question.
Jan 11 '08 #6

P: 41

I think im using the word "column" where i shouldnt be.(i think i was probably referign to fields, not columns)

I have it more or less sorted now. Now all i need to do is be able to check records on a seperate table to the one my form is linked too.
Jan 11 '08 #7

Post your reply

Sign in to post your reply or Sign up for a free account.