Preventing user from opening wrong record in listbox

M

Mo

In the double-click event of a list box I have the following code to allow
users to open another form and view a related record based on the selected
row in the list box. It's very standard VBA:

docname = "PatientDetails"
lkCriteria = " [id] = forms![SearchForm]![list_main] "
DoCmd.OpenForm docname, , , lkCriteria

I have noticed though that if a user does not first select the row, but
doubles-clicks in the list box but well away from any records, this opens up
the other form, but with an empty record. I have tried to prevent this with:

If Me.[list_main].RowSource = False Then

MsgBox ("You have not selected a row"), vbOKOnly
Exit Sub

End If

This portion of the code is not working. Can anyone point out what I'm doing
wrong. TIA for any help.

Mo
 
C

Chris L via AccessMonster.com

If no record is selected in a list box then it returns Null, so change the
code to:-

if isnull(Me.[list_main]) Then
....


hth
Chris
In the double-click event of a list box I have the following code to allow
users to open another form and view a related record based on the selected
row in the list box. It's very standard VBA:

docname = "PatientDetails"
lkCriteria = " [id] = forms![SearchForm]![list_main] "
DoCmd.OpenForm docname, , , lkCriteria

I have noticed though that if a user does not first select the row, but
doubles-clicks in the list box but well away from any records, this opens up
the other form, but with an empty record. I have tried to prevent this with:

If Me.[list_main].RowSource = False Then

MsgBox ("You have not selected a row"), vbOKOnly
Exit Sub

End If

This portion of the code is not working. Can anyone point out what I'm doing
wrong. TIA for any help.

Mo
 
Top