Results 1 to 10 of 10
  1. #1
    Join Date
    Feb 2005
    Posts
    31

    Exclamation Unanswered: If Content from Listbox Not Select, Then Return Error Msgbox. Can you help?

    Hello. I was wondering if you could help me figure out why is it that MS Access gives me an error message saying:

    "Argument is not optional."

    Here's my code so far...

    If (SupervisorListbox.Selected) = False Then
    MsgBox "Please select a Supervisor from supervisor listbox first."

    Else

    On Error GoTo Err_cmdAddAgent_Click

    Dim stDocName As String
    Dim stLinkCriteria As String

    stDocName = "AddToAgent"
    DoCmd.OpenForm stDocName, , , stLinkCriteria

    Exit_cmdAddAgent_Click:
    Exit Sub

    Err_cmdAddAgent_Click:
    MsgBox Err.Description
    Resume Exit_cmdAddAgent_Click

    End If
    End Sub

  2. #2
    Join Date
    Sep 2003
    Location
    MI
    Posts
    3,713
    And this is on what line?????
    Back to Access ... ADO is not the way to go for speed ...

  3. #3
    Join Date
    Feb 2005
    Posts
    31
    Sup Listbox

    Agent Listbox

    [Add Agent] Button

    Considering that I do not understand your question, the goal of this sub is not let end user click on [Add Agent] before selecting a Supervisor from Sup Listbox.

    Hope this clarifies...

  4. #4
    Join Date
    Feb 2005
    Posts
    31
    Sorry, I got ya! It's on the IF... Line

  5. #5
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    your choice:
    If (SupervisorListbox.Selected = False) Then
    or
    If SupervisorListbox.Selected = False Then

    izy
    currently using SS 2008R2

  6. #6
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    ...but i have never played with .selected (if it exists)

    so maybe try
    if isnull(supervisorlistbox) then

    izy
    currently using SS 2008R2

  7. #7
    Join Date
    Apr 2004
    Location
    Derbyshire, UK
    Posts
    789
    Provided Answers: 1
    Hi

    Is it a multi-select list box ?

    If it is then you need an argument ie.

    IF Not SupervisorListbox.Selected (i) then
    ...Not selected Code
    else

    where i is the list index position (zero based).

    You will need to check all value of i for the list (ie SupervisorListbox.ListCount - 1)


    If it is not multi-select then try

    IF SupervisorListbox.ListIndex < 0 then
    ... no selection code

    else


    I suggest you look at help file for the list box Selected property.

    HTH


    MTB

    If t nos not a muli delect list box then ty

  8. #8
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    I'm not sure that you can have the endif after the error handler
    I'd suggest moving the endif to before the start of the error handling code

    IE
    Code:
    If (SupervisorListbox.Selected) = False Then
    MsgBox "Please select a Supervisor from supervisor listbox first."
    
    Else
    
    On Error GoTo Err_cmdAddAgent_Click
    
    Dim stDocName As String
    Dim stLinkCriteria As String
    
    stDocName = "AddToAgent"
    DoCmd.OpenForm stDocName, , , stLinkCriteria
    END IF
    Exit_cmdAddAgent_Click:
    Exit Sub
    
    Err_cmdAddAgent_Click:
    MsgBox Err.Description
    Resume Exit_cmdAddAgent_Click
    End Sub

  9. #9
    Join Date
    Sep 2004
    Location
    Tampa, FL
    Posts
    520
    I believe you are using the wrong function.
    Selected is used thave VB make a selection from a list box.
    the selected Function has to have something in the parenthesis after it, it is not an optional argument. IE.. (Qouting Access help) Me.Listbox.Slected(4) selects the fith choice in a listbox.
    I believe whjat you are looking for is something like

    If me.listbox Is Null then
    doCmd.ptch a fit
    End if
    the rest of my save code
    my error handling.

    That's my 2 cents I could be wrong.
    Darasen

  10. #10
    Join Date
    Apr 2004
    Location
    Derbyshire, UK
    Posts
    789
    Provided Answers: 1
    Hi

    Quoting Access Help

    "The Selected property is a zero-based array that contains the selected state of each item in a list box."

    This is valid only if the listbox is set to Simlpe or extended (ie not None).

    This is a boolian array, therefore to select the fith element you use the statement

    ListBox.Selected(4) = True

    This is only the case if it if Multi-selelect. Also if multi-select, the value of the list box is always Null. Therefore, for a multi-select type listbox, 'If ListBox Is Null' will always be true !!

    MTB

Posting Permissions

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