Use item selected from listbox to open new form for selected record

shenlee

Registered User.
Local time
Today, 01:44
Joined
Mar 28, 2003
Messages
16
I have a listbox on a form. It is not multi-select. I want the user to pick one item from the list and click on a command button which will open another form at the record selected in the list box. The command button on-click property involes an event procedure which includes the line DoCmd.OpenForm stDocName, , , "ItemID=intItemChosen". intItemChosen contains the itemID of the record I want to open but I keep getting a pop-up window asking me for the item id. I want the form to open without the pop-up appearing. Does anybody know how to do this?
 
Try this:

DoCmd.OpenForm stDocName, , , "ItemID = " & intItemChosen
 
THANKS! It works now!
It's amazing how one small error in code can cause so many problems!
 
Where do you put this such code.

Do I put this as a click option in the listbox?

if so, then what variables in that statement am I suppose to change to work for me.

I changed what I though and got the following error message:

"runtime error 2494"
"The action or method requires a form name argument"

This is where I put this statement:

Private Sub searchlist_DblClick(Cancel As Integer)
DoCmd.OpenForm stDocName, , , "employeeID = " & intItemChosen
End Sub
 
JonatABS said:
Where do you put this such code.

As the original post stated, the code goes in the form's module under the OnClick event of the command button.

With the code you have givem please note that intItemChosen is a variable created by the original poster and should be changed in your code.
 
Your right. I appoligize, ive just have a crappy day and im not thinking straight anymore, time to go home and get away

thanks and sorry about that
 

Users who are viewing this thread

Back
Top Bottom