QtheNovice
QtheNovice

Reputation: 95

multiple problems with listbox on form

I'm a novice using Access 2003, and I've got a form bound to a query called AlphaAcctQ (which alphabetizes the account names from a table - AccountT). On the form is an unbound list box which displays the account names from the query and returns the numerical AcctID for the selected account.

There is command button on the form, "CreateInv." When clicked, I'd like it to display an error message if nothing is selected in the listbox, but when I write

Call MsgBox("AcctList.Value = " & AcctList.Value, vbOKOnly)    
    If AcctList.Value = Null Then
    Call MsgBox("You must select an account first.", vbOKOnly)
    'Else
        'If subform returns no values Then
            'Call MsgBox with another error code
        'End If
   'run an append query
    End If

...then I get a box that says "AcctList.Value =" (which was a test to show me what the AcctList listbox was returning as a value) but nothing else happens. I even set the default value of AcctList to "=Null" in its properties, but that didn't change anything.

I've commented out the structure of some code I haven't written yet, because that's supposed to give me an error message if there aren't values in the subform, and if I can't even figure out how to generate an error message if the listbox has nothing selected in it, then I have no idea how to even start that code.

So, how can I write an IF statement for if nothing is selected in the listbox? What about another IF statement for if the subform (which is based on another query that selects invoice items fitting the criterion of the selected account in the AcctList listbox in the main form)?

Thanks.

Upvotes: 1

Views: 351

Answers (1)

Andy G
Andy G

Reputation: 19367

It took me a while to work out what you were asking: how can I determine if nothing is selected in a ListBox. The simplest approach:

If AccList.ItemsSelected.Count = 0 Then
    MsgBox "Nothing selected"
End If

Upvotes: 1

Related Questions