Listbox Selection

  • Thread starter Thread starter Asif
  • Start date Start date
A

Asif

Hi all

I have two listbox's in my form and they are both run from two
different queries. Below each listbox is a command button (Delete)
used to delete an entry in the listbox.

Now behind the command button for listbox 1 I have the following code;

If Nz(Me!List1, "") = "" Then
MsgBox "Nothing Selected"
Else
Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "8-b COPPERBINDELETE"

stLinkCriteria = "[BINPROCESSID]=" & Me![txtBinProcessID]
DoCmd.OpenForm stDocName, , , stLinkCriteria

End If
End Sub

Now If I don't click a selection from listbox 1 then an error message
appears saying "Nothing selected" now I've tried to apply the same
code to the command button of listbox 2 but it doesn't work

If Nz(Me!List2, "") = "" Then
MsgBox "Nothing Selected"
Else
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "9-b GENERALBINDELETE"
stLinkCriteria = "[BINPROCESSID]=" & Me![txtBinProcessID]
DoCmd.OpenForm stDocName, , , stLinkCriteria
End If
End Sub

The code continues to run even if nothing is selected from listbox 2.

Any ideas why this is happening and how to go about resolving this
issue?

Thanks
 
Hi all

I have two listbox's in my form and they are both run from two
different queries. Below each listbox is a command button (Delete)
used to delete an entry in the listbox.

Now behind the command button for listbox 1 I have the following code;

If Nz(Me!List1, "") = "" Then
MsgBox "Nothing Selected"
Else
Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "8-b COPPERBINDELETE"

stLinkCriteria = "[BINPROCESSID]=" & Me![txtBinProcessID]
DoCmd.OpenForm stDocName, , , stLinkCriteria

End If
End Sub

Try something like this:

If Nz(Me.List1.Column(0), 0) =0 Then
Msgbox "Nothing Selected"
Exit Sub
End If

Now If I don't click a selection from listbox 1 then an error message
appears saying "Nothing selected" now I've tried to apply the same
code to the command button of listbox 2 but it doesn't work

If Nz(Me!List2, "") = "" Then
MsgBox "Nothing Selected"
Else
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "9-b GENERALBINDELETE"
stLinkCriteria = "[BINPROCESSID]=" & Me![txtBinProcessID]
DoCmd.OpenForm stDocName, , , stLinkCriteria
End If
End Sub

The code continues to run even if nothing is selected from listbox 2.

Any ideas why this is happening and how to go about resolving this
issue?

Thanks

Scott McDaniel
scott@takemeout_infotrakker.com
www.infotrakker.com
 
Asif said:
Hi all

I have two listbox's in my form and they are both run from two
different queries. Below each listbox is a command button (Delete)
used to delete an entry in the listbox.

Now behind the command button for listbox 1 I have the following
code;

If Nz(Me!List1, "") = "" Then
MsgBox "Nothing Selected"
Else
Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "8-b COPPERBINDELETE"

stLinkCriteria = "[BINPROCESSID]=" & Me![txtBinProcessID]
DoCmd.OpenForm stDocName, , , stLinkCriteria

End If
End Sub

Now If I don't click a selection from listbox 1 then an error message
appears saying "Nothing selected" now I've tried to apply the same
code to the command button of listbox 2 but it doesn't work

If Nz(Me!List2, "") = "" Then
MsgBox "Nothing Selected"
Else
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "9-b GENERALBINDELETE"
stLinkCriteria = "[BINPROCESSID]=" & Me![txtBinProcessID]
DoCmd.OpenForm stDocName, , , stLinkCriteria
End If
End Sub

The code continues to run even if nothing is selected from listbox 2.

Any ideas why this is happening and how to go about resolving this
issue?

Thanks

Another way of testing whether a selction is made, is to test the
..ListIndex property, where a return value of -1 indicates no
selection

If Me!lstMyList.ListIndex = -1 Then
' no selection
Else
' something is selected
End If
 
Back
Top