dlookup help

fakiane

New member
Local time
Today, 23:41
Joined
Dec 14, 2016
Messages
8
i'm trying to use dlookup to look up the price of a product based on a combo box selection. here's the expression I have so far but it doesn't seem to be working

=DLookUp("[Price]","[Stock]","[Product Name]=" & Str([combo12]))
 
If there is text in a combo box,you don't need to use STR,
But
You DO have to use quotes to define strings

DLookup(field,table,"[field]='" & cboBox & "'")
 
DLookup(field,table,"[field]='" & cboBox & "'")

Common sense dictates that a field named [Product Name] is, in fact, Text, so Ranman256's syntax should work...assuming that [Product Name] is the Bound Column for the Combobox, which may or may not be true! When using the Combobox Wizard, the Access Gnomes will add the PK from the underlying Table, even if the developer doesn't include it, and then proceed to make it the Bound Column!

If Ranman256's code doesn't work for you, add this in your code window:

Code:
Private Sub combo12_AfterUpdate()
 MsgBox Me.combo12
End Sub
Now make a selection from the Combobox...does the Messagebox display the [Product Name] or something else?

Linq ;0)>
 
If there is text in a combo box,you don't need to use STR,
But
You DO have to use quotes to define strings

DLookup(field,table,"[field]='" & cboBox & "'")

i tried this but it comes up with #name?
=DLookUp([Price],[Stock],"[Price]='" & [cboBox] & "'products") is the code I used, 'products' is what I re-named the combo box
 
Common sense dictates that a field named [Product Name] is, in fact, Text, so Ranman256's syntax should work...assuming that [Product Name] is the Bound Column for the Combobox, which may or may not be true! When using the Combobox Wizard, the Access Gnomes will add the PK from the underlying Table, even if the developer doesn't include it, and then proceed to make it the Bound Column!

If Ranman256's code doesn't work for you, add this in your code window:

Code:
Private Sub combo12_AfterUpdate()
 MsgBox Me.combo12
End Sub
Now make a selection from the Combobox...does the Messagebox display the [Product Name] or something else?

Linq ;0)>

its coming up with random numbers
 

Users who are viewing this thread

Back
Top Bottom