I have created another list box to try this method and get the same error
on
the if I comment out the error line the error goes to the next line. The
text boxes are set to =DLookUp("SumofNetAvail","qryNetAvailQty") when the
form loads.
Private Sub lstMainItems_Click()
lstItem = Me.lstMainItems.Column(1)
Me.txtOH = Me.lstMainItems.Column(4)
Me.txtNetDollars = Me.lstMainItems.Column(8) "Error HERE"
Me.txtprojqty = Me.lstMainItems.Column(6)
Me.txtNetQty = Me.lstMainItems.Column(5)
Me.txtOHDollars = Me.lstMainItems.Column(7)
Me.txtProDollars = Me.lstMainItems.Column(9)
End Sub
Beetle said:
Rather than using a collection of DLookup statements, why not
add those fields as columns in your list box, then set the Control
Source of each text box to the appropriate column. So each
text box would have a Control Source like;
=[lstItem].Column(x)
where x is the numeric value of each column in the query. It is a
zero based index, so the first column is Column(0), the second is
Column(1), etc.
_________
Sean Bailey
Rpettis31 said:
I do not understand the DLookup very well apparently as I am getting a
runtime error 2448 from this code. I was trying to get the values
associated
with the item selected to fill in the text boxes. I am assuming there
is
a
better way to do this?
Me.txtprojqty.Value = DLookup("Projected", "tblInventory3", "Item = " &
"'"
& lstItem & "'")
Me.txtNetQty = DLookup("NetAvail", "tblInventory3", "Item = " & "'" &
lstItem & "'")
Me.txtOHDollars = DLookup("DollarsOH", "tblInventory3", "Item = " & "'"
&
lstItem & "'")
Me.txtProDollars = DLookup("ProjectedDollars", "tblInventory3", "Item =
"
&
"'" & lstItem & "'")
:
Thanks for your help, I always forget the " ' " in the syntax...
:
You don't tell us what problem you are having, so here is a guess:
1. Need to declare lstItem:
dim lstItem as variant
2. Line with dlookup should be:
Me.txtOH = DLookup("TotalOH", "tblInventory3", "Item = " & "'" &
lstItem &
"'") ' if Item is text, or
Me.txtOH = DLookup("TotalOH", "tblInventory3", "Item = " & lstItem )
'
if it
is numeric
Damon
Private Sub List8_Click()
lstItem = Me.List8.Column(1)
Me.txtOH.ControlSource = DLookup("TotalOH", "[tblInventory3]",
"Item
=" &
lstItem)
End Sub