Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DLookup Sub or Function not Defined

Status
Not open for further replies.

NeoMatrix1217

IS-IT--Management
Apr 5, 2005
7
US
I have a Combobox called ComboBox1 it gets populated by doing a loop in a access database untill it has filled up. I want to be able to use the selected item in that combobox to populate a textbox from the same database. I have tried the DLookup in VBA but I can seem to get it to work here is the code. When I step into it stops at DLookup with a compile error: sub or function not defined : (


Please Help

Private Sub ComboBox1_AfterUpdate()

TextBox1.Value = DLookup("TText", "Template", "TText='" & ComboBox1.Value & " '")

End Sub
 



Hi,

DLookup is a spreadsheet function. Help is in Excel, not VBA.

To reference most spreadsheet functions in VBA...
Code:
TextBox1.Value = [b]Applicetion.[/b]DLookup("TText", "Template", "TText='" & ComboBox1.Value & " '")


Skip,

[glasses]Just traded in my old subtlety...
for a brand NUANCE![tongue]
 
Thanks for the quick response and actually I am using this in MS Word I notice that DLookup does not appear in the drop down list.
 




Have you set a reference to MS Access Tools > References...?

Skip,

[glasses]Just traded in my old subtlety...
for a brand NUANCE![tongue]
 
I don't see MS Access tools in the references I only see Microsoft Access 12.0 Object library.
 



I was not referring to MS Access Tools. I was referring to the Tools > References menu for the MS Access reference. Is it checked? It should, and maybe then you can reference that applications function library.

Skip,

[glasses]Just traded in my old subtlety...
for a brand NUANCE![tongue]
 
Yes under Tool--> References Microsoft Access 12.0 object library is checked but when I do trxtbox1.value = application. --> the drop down box does not show dlookup.

sorry for my ignorance in this matter.

Thanks for all your help.
 
Ok i got the refernce doing it this way?

TextBox1.Value = Access.Application.DLookup("TText", "Template", "TText='" & ComboBox1.Value & " '")

but now I get a Run-time error '2950':
reserved error
 
Got it to work this was the code that did it

TextBox1.Value = Access.Application.DLookup("TText", "Template", "TID='" & ComboBox1.Value & " '")

thanks for pointing me in the right direction.
 




How about...
Code:
TextBox1.Value = Access.Application.DLookup("[TText]", "[Template]", "[TText]='" & ComboBox1.Value & " '")
Strange, you're returning [TText] AND you are supplying a criteria value for [TText], so I'd expect that the value returned would be identical to the value in ComboBox1.Value.

Skip,

[glasses]Just traded in my old subtlety...
for a brand NUANCE![tongue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top