Listbox help.

L

Lee Taylor-Vaughan

hello group,

I have an unbound form, with a list box (lstDispmain) on it. the primary key
tothe list box is controlnumberID.

I want to be able to double click a single entry on the list box and open up
that record. how can i do this by referring to the controlnumberID in the
listbox, and opening that form?

the code below opens a blank record.

thanks in advance

lee

CODE:

Private Sub cmdOpenMission_Click()
On Error GoTo Err_cmdOpenMission_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmActivity"

stLinkCriteria = "[ControlNumberID]=" & "'" & Me![lstDispMain] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_cmdOpenMission_Click:
Exit Sub

Err_cmdOpenMission_Click:
MsgBox Err.Description
Resume Exit_cmdOpenMission_Click

End Sub
 
D

Don Wilson

From what i can see you are trying to set the criteria
through the code window but not the recordset.

I would go to the forms record source and set the criteria
there.

The criteria would simply be the listbox's control number
ID. then on click or double click requery the subform.

DoCmd.Requery "Forms!MainForm!SubForm"

I hope that helps.
 
G

Graham Mandeno

Hi Lee

Make sure that the BoundColumn property of your listbox is set to the column
from the RowSource which contains the ControlNumberID. (1 indicates the
first column, etc, unlike the .Column( ) property, which is zero-based)

Also, is ControlNumberID a numeric field? If so, then get rid of the single
quotes:
stLinkCriteria = "[ControlNumberID]=" & Me![lstDispMain]

If it still doesn't work, set a breakpoint on the DoCmd.OpenForm line and
examine the value of stLinkCriteria to see if anything hits you between the
eyes :)
 
L

Lee Taylor-Vaughan

It works great. i was number field and i set the bound column to 1..

thanks

(this newsgroup is awesome!)

Graham Mandeno said:
Hi Lee

Make sure that the BoundColumn property of your listbox is set to the column
from the RowSource which contains the ControlNumberID. (1 indicates the
first column, etc, unlike the .Column( ) property, which is zero-based)

Also, is ControlNumberID a numeric field? If so, then get rid of the single
quotes:
stLinkCriteria = "[ControlNumberID]=" & Me![lstDispMain]

If it still doesn't work, set a breakpoint on the DoCmd.OpenForm line and
examine the value of stLinkCriteria to see if anything hits you between the
eyes :)
--
Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand

Lee Taylor-Vaughan said:
hello group,

I have an unbound form, with a list box (lstDispmain) on it. the primary key
tothe list box is controlnumberID.

I want to be able to double click a single entry on the list box and
open
up
that record. how can i do this by referring to the controlnumberID in the
listbox, and opening that form?

the code below opens a blank record.

thanks in advance

lee

CODE:

Private Sub cmdOpenMission_Click()
On Error GoTo Err_cmdOpenMission_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmActivity"

stLinkCriteria = "[ControlNumberID]=" & "'" & Me![lstDispMain] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_cmdOpenMission_Click:
Exit Sub

Err_cmdOpenMission_Click:
MsgBox Err.Description
Resume Exit_cmdOpenMission_Click

End Sub
 

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