dbTalk Databases Forums  

How To Bring up form by dblclick in listbox

comp.database.ms-access comp.database.ms-access


Discuss How To Bring up form by dblclick in listbox in the comp.database.ms-access forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
mmi
 
Posts: n/a

Default How To Bring up form by dblclick in listbox - 11-06-2003 , 01:21 PM






Hi all!

I am somewhat new to MS Access. I created a database with customer info in
it. I created a search form with a text box for typing in a last name or
part of a last name and a list box that shows all appropriate matches from
the text box. I now want to be able to click or dblclick on one of the
appropriate names in the list box to open up the edit form for that person.
How do I go about doing this? I have spent about two weeks researching and
tearing down a similar database only to get nowhere. Any help would be
greatly appreciated.

Thanks



Reply With Quote
  #2  
Old   
John
 
Posts: n/a

Default Re: How To Bring up form by dblclick in listbox - 11-06-2003 , 07:52 PM






2 weeks eh? Well I guess that is suffrage enough.

Your ListBox has an On DClick Event. You can find it in the listboxes
properties (rclick the control and select properties). To the right of
the events textbox in the properties window, when you make that
textbox active, you see "..." indicating that you can build something
there. Click the "..." and select "code" then you will be placed in
the forms VBA module with your dclick procedure created for you,
prepared to do nothing at all. If you add a siple line like:

MsgBox Me.myList.Value

right above the End Sub directive then everytime you dclick the list
it will display the selected value in a msgbox.

Well you don't need a MsgBox, you want to open a form. To see the code
that access builds for you to do such a thing add a temporary command
button to your form. A wizard pops up that will walk you through a
series of choices, choose "form operations", then "open form", then
finish the wizard by selecting which form the button click should
open. If you want the form to locate a record matching the selected
ListBox Item then after you select the form to open tell the wizard to
open the form and find specific data. the next screen asks you to
match up your controls on each form that contain matching data.

Now that you have this button that will open a form of your choosing
make the button active and look under events in the propties window.
you will see that access has created an on Click Event. Open it.

The important lines here will be in the topmost part of the
function...

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmMyForm"

stLinkCriteria = "[State]=" & "'" & Me![MyListBox] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria

copy these lines (hilight and ctrl-c) and find your dclick event
again, should be in the same window, above or below.

Paste these lines into your procedure in the place of your MsgBox
command that is there now. Now save your module, open your form (with
the listbox) and dclick the listbox. Magic! (well, just a bit of code
really, but shhhh

You will notice that the form is locked to that single matching
record, if this is not the behavior you want, then you can
programatically change the forms criteria on load.

I leave that exercise to you and if you can't figure it out I'll see
you in another 2 weeks

regards,

John
jobrien at acscience dot com






"mmi" <mikehigh3 (AT) mchsi (DOT) com> wrote

Quote:
Hi all!

I am somewhat new to MS Access. I created a database with customer info in
it. I created a search form with a text box for typing in a last name or
part of a last name and a list box that shows all appropriate matches from
the text box. I now want to be able to click or dblclick on one of the
appropriate names in the list box to open up the edit form for that person.
How do I go about doing this? I have spent about two weeks researching and
tearing down a similar database only to get nowhere. Any help would be
greatly appreciated.

Thanks

Reply With Quote
  #3  
Old   
mmi
 
Posts: n/a

Default Re: How To Bring up form by dblclick in listbox - 11-06-2003 , 09:36 PM



THANKS ALOT!!!

I can't believe how simple that was! Everything is now working exactly as I
wanted (until I decide on more changes)

Any other questions, you bet I will be back to this newsgroup.

Thanks again
Mike
"John" <jobrienct (AT) excite (DOT) com> wrote

Quote:
2 weeks eh? Well I guess that is suffrage enough.

Your ListBox has an On DClick Event. You can find it in the listboxes
properties (rclick the control and select properties). To the right of
the events textbox in the properties window, when you make that
textbox active, you see "..." indicating that you can build something
there. Click the "..." and select "code" then you will be placed in
the forms VBA module with your dclick procedure created for you,
prepared to do nothing at all. If you add a siple line like:

MsgBox Me.myList.Value

right above the End Sub directive then everytime you dclick the list
it will display the selected value in a msgbox.

Well you don't need a MsgBox, you want to open a form. To see the code
that access builds for you to do such a thing add a temporary command
button to your form. A wizard pops up that will walk you through a
series of choices, choose "form operations", then "open form", then
finish the wizard by selecting which form the button click should
open. If you want the form to locate a record matching the selected
ListBox Item then after you select the form to open tell the wizard to
open the form and find specific data. the next screen asks you to
match up your controls on each form that contain matching data.

Now that you have this button that will open a form of your choosing
make the button active and look under events in the propties window.
you will see that access has created an on Click Event. Open it.

The important lines here will be in the topmost part of the
function...

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmMyForm"

stLinkCriteria = "[State]=" & "'" & Me![MyListBox] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria

copy these lines (hilight and ctrl-c) and find your dclick event
again, should be in the same window, above or below.

Paste these lines into your procedure in the place of your MsgBox
command that is there now. Now save your module, open your form (with
the listbox) and dclick the listbox. Magic! (well, just a bit of code
really, but shhhh

You will notice that the form is locked to that single matching
record, if this is not the behavior you want, then you can
programatically change the forms criteria on load.

I leave that exercise to you and if you can't figure it out I'll see
you in another 2 weeks

regards,

John
jobrien at acscience dot com






"mmi" <mikehigh3 (AT) mchsi (DOT) com> wrote

Hi all!

I am somewhat new to MS Access. I created a database with customer info
in
it. I created a search form with a text box for typing in a last name
or
part of a last name and a list box that shows all appropriate matches
from
the text box. I now want to be able to click or dblclick on one of the
appropriate names in the list box to open up the edit form for that
person.
How do I go about doing this? I have spent about two weeks researching
and
tearing down a similar database only to get nowhere. Any help would be
greatly appreciated.

Thanks



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.