Using a Listbox's RowSource in a Dlookup

  • Thread starter Nicholas Scarpinato
  • Start date
N

Nicholas Scarpinato

I have a form with a textbox that I'm using as a search function. The user
types a PO number into this text box, and the AfterUpdate of the textbox runs
some code to search for the vendor and the batch of items that PO number is
attached to. The code then selects the appropriate vendor and batch from the
respective fields on the form and runs those fields' DblClick procedures to
emulate a user selecting the information manually. What I need to do is give
the user a warning message if the vendor or batch related to that PO is not
available on the form they are currently using. The form I'm working on is
used for marking items as credited, so if a PO has already been credited, I
want to let the user know this. The best way I can think of to do this is to
do a Dlookup on the PO number to bring back the batch information and compare
it to the list of batches in the form's Batch Selection listbox, but I don't
know how to do this. Basically, the code would look something like this:

Batch = Dlookup("Batch","tblMain","PONumber = '" & Me!PONumber & "'")
ListboxList = Dlookup("Batch", {the listbox's recordset}, "Batch = '" &
Batch & "'")
If IsNull(ListboxList) = True Then
Msgbox "This PO has already been credited."
Else
Me!Listbox = Batch

where Batch is the batch name associated with the PO number, and ListboxList
is the lookup to see if that Batch is contained within the listbox. If Batch
is not contained in the listbox, display the error message, otherwise set the
listbox to equal Batch.

I am pulling the listbox items from a query which is driven by the
information in the vendor selection listbox. I've tried using this query as
part of my Dlookup expression, but it doesn't seem to work.
 

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