Results 1 to 4 of 4
  1. #1
    Join Date
    Aug 2004
    Posts
    364

    Unanswered: Message Box problem when two listboxes have a row selected - can anyone help?

    Hello, I have the following code in the on-click of a command button. The code is supposed to check to ensure that two listboxes (list2361 for Groups and list21 for users) each have a row selected. If they do, the insert section of code is executed.

    I am having a problem with the code below, even if I select a row in both listboxes I always get the message "Please Select A User" and I cannot work out what is wrong with the code.

    Can anyone help?

    Code:
    user_selected = True
    group_selected = True
    
    If IsNull(Me!List21) Then
    user_selected = False
    End If
    
    If IsNull(Me!List2361) Then
    group_selected = False
    End If
    
    If user_selected = False Or group_selected = False Then
    
    If user_selected = False And group_selected = False Then MsgBox "Please Select A user And A Group!"
    
    If user_selected = False And group_selected = True Then MsgBox "Please Select A user!"
    
    If user_selected = True And group_selected = False Then MsgBox "Please Select A Group!"
    
    Exit Sub
    End If
    
    If Nz(DLookup("userID", "tblLinkuserGroups", "userID = " & Me.List21.Column(0) & " And groupID = " & List2361), 0) = 0 Then
     
    Dim strSQL As String
    strSQL = "INSERT INTO tblLinkuserGroups (userID, groupID ) Values (" & [Forms]![visits_frm]!List21.Column(0) & ", " & [Forms]![visits_frm]!List2361.Column(0) & ");"
    DoCmd****nSQL strSQL
          
    
    Me.List21.Requery
    Else
    MsgBox "Duplicate Warning! The selected user is already a member of the selected group!"
    Exit Sub
    End If
    Thankyou!
    Last edited by moss2076; 06-09-11 at 17:24.

  2. #2
    Join Date
    Aug 2004
    Posts
    364
    I think I've fixed the issue by noticing that one of the listbox properties had its Multi Select option set to "extended". Setting it to "No" appears to have fixed the issue.

  3. #3
    Join Date
    Aug 2004
    Posts
    364
    I think I've fixed the issue by noticing that one of the listbox properties had its Multi Select option set to "extended". Setting it to "None" appears to have fixed the issue.

  4. #4
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    Glad you got it fixed! The trigger for the problem lay with your statements like

    If IsNull(Me!ListboxName)

    You're saying, in essence

    If the Value of this Listbox is Null, then this

    Variable = False

    Access will always evaluate this part of the statement as True, because a Listbox set to MultiSelect doesn't have a Value! The Listbox loses its Value Property when set to MultiSelect.

    Kudos for figuring it out yourself!

    Linq ;0)>
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •