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

ListBox Row Click Event

P: 14
Hi all

Is there any event for list box row click/double click.I want to open a new form based on the row selected and when it is clicked.I know there's one for the whole list box but i am looking for a row click event.I want to know if there is such an event or any other way to implement this.


thanks
Sree
Jan 20 '09 #1
Share this Question
Share on Google+
10 Replies


DonRayner
Expert 100+
P: 489
Hi Sree, How about using the after update event to trigger opening the form.
Jan 20 '09 #2

Megalog
Expert 100+
P: 378
There is no row specific event. Basically you need to code whatever routine you need, to look at the selected row(s) and perform whatever function it is you're trying to do. Check out the help file on the listbox's 'Selected', 'ListCount', and 'Column' properties. Using those you should be able to come up with a nice loop that runs through your listbox's rows and performs whatever function you need on the selected row's data.

If you need anything more specific, then please post whatever it is you're specifically trying to do, with example data. I know you said you're trying to open forms, but based on what?

-Mega
Jan 20 '09 #3

P: 14
don

thanks for the help.i'll try that.

Megalog

i am populating employee info in the list box and each record refers to one employee.What i am trying to do is open the selected employee details page/form when i click on the particular record/row.I have Employee Last Name ,First Name ,UserName(primarykey),Email in the listbox.I want the specific form to be opened on some double click event rather than a single click.

hope this helps
Sree
Jan 20 '09 #4

Megalog
Expert 100+
P: 378
"UserName" is the primary key for the employee table? This isnt a text value is it? You do have a normal numeric unique PK in that table as well, I hope? I've seen where people use the full name in the contacts/employee table as the PK, and it can get ugly once you get two employees named John Smith, etc.

Also, what is the name of the form you want opened?
Jan 20 '09 #5

P: 14
Megalog

Yes UserName is the primary key.Its the same as the email id without the domain name so its always unique(something like for outlook exchange).

thanks
Sree
Jan 20 '09 #6

Megalog
Expert 100+
P: 378
Expand|Select|Wrap|Line Numbers
  1. Dim varRow
  2. Dim varID
  3. varRow = Me.List0.ListIndex + 1
  4. varID = Me.List0.Column(2, varRow)
  5.  
  6. 'Use this if UserName is a numeric value
  7. DoCmd.OpenForm "Contact Details", , , "[UserName]=" & varID
  8.  
  9. 'Use this if UserName is a text value
  10. DoCmd.OpenForm "Contact Details", , , "[UserName]='" & varID & "'"
Replace "List0" with your listbox name. From what you said before, I'm assuming UserName is the 3rd column in your listbox. If it isnt (if you have hidden values, etc) then adjust the VarID above so that the number is whichever column it's in, minus 1. (first column starts at zero).

You didnt state what the name of the form you're opening was, so replace my "Contact Details" with the formal form name.. and you should be set. Also, Comment out or delete whichever DoCmd.OpenForm line doesnt apply (depending on whether UserName is numeric or text).
Place all that code in the doubleclick event on the listbox and give it a shot.


-Mega
Jan 20 '09 #7

P: 14
I laid out a basic prototype and it seems to work on the double click event but i still have to do some more background work to populate the form details which i can do.

thanks for your help
Sree
Jan 20 '09 #8

P: 14
Megalog

I tried to use the command

DoCmd.OpenForm "Individual_Info", , , "[UserName]='" & rs!UserName & "'"

and i get this error on double click

"run time error 2491 :the action or method is invalid because form is not bound to table/query"

any idea what i am doing wrong??

thanks
Sree
Jan 21 '09 #9

Megalog
Expert 100+
P: 378
Well it seems the error message is going to ask the same thing I'm going to ask... is the form bound to a table or query? Go to it's recordsource property and see if a table/query name, or a select statement is there. And if there is, make sure 'Username' is a valid field within that source.

If you open the form manually, are you able to cycle through all the existing user records? If so, then it's bound to that data.

If not, then what exactly is the intended function of this form? I assumed it was bound to a user table, that you wanted to pop open to see all the user's full details from a list box. The better you explain things, the better I can help. =)
Jan 21 '09 #10

P: 42
oiuokloooooooooooooooooooooooooooo
May 19 '09 #11

Post your reply

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