Setting variable to list box value

D

Diane

I have a simple system for setting up check requests for bills that
need to be paid. I have a form with a list box which lists all the
bills that need processing. The user selects bills from this box that
should be paid on the same check and clicks a button that creates a
check record in the Checks table and links each of the selected bills
to that CheckID. All of this works rather slickly.

However, I want to ensure, before a new check is created, that all the
selected bills are for the same PayeeID. The pertinent bits of code I
have thus far are:

Dim dbs As Database
Dim BillsList As Control
Dim lngPayee As Long
Dim varItem As Variant
Dim intMsgValue As Integer

Set dbs = CurrentDb
Set BillsList = Me.BillsList
lngPayee = BillsList.Column(5,0)

'Verify that all selected bills are for the same payee
For Each varItem In BillsList.ItemsSelected
If BillsList.Column(5, varItem) <> lngPayee Then
intMsgValue = MsgBox("All selected bills must be for the
same payee. Please amend your selection.", _
vbOKOnly, "Conflicting Payee Information")
BillsList.SetFocus
DeselectAllButton_Click 'runs a sub to clear the
list box
GoTo Exit_RequestCheckButton_Click 'exits sub
End If
Next

This works okay as long as the first item in the list box is selected.
However, I would like to set lngPayee equal to the value of column 5
of the first SELECTED item in the list box, and cannot figure out how
to reference that row number.

Also, can anyone tell me why I have no luck displaying message boxes
unless I set them equal to a variable? I've seen many example lines of
code that just start with "MsgBox ..." but I get an error that an "="
is expected every time I do this. The variable thing works, but seems
sloppy to me, since I don't really need the value for anything.

Thanks in advance for any help!

Cheers,
Diane
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top