Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / General 2 / June 2007

Tip: Looking for answers? Try searching our database.

Listbox Selection

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Asif - 29 Jun 2007 10:49 GMT
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
Scott McDaniel - 29 Jun 2007 12:02 GMT
>Hi all
>
[quoted text clipped - 17 lines]
>End If
>End Sub

Try something like this:

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

<other code here>

>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
[quoted text clipped - 17 lines]
>
>Thanks

Scott McDaniel
scott@takemeout_infotrakker.com
www.infotrakker.com
RoyVidar - 29 Jun 2007 12:28 GMT
"Asif" <asifhashmani@hotmail.com> wrote in message
<1183110599.248444.316170@k29g2000hsd.googlegroups.com>:
> Hi all
>
[quoted text clipped - 40 lines]
>
> 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

Signature

Roy-Vidar

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.