Solved

Ms Access - DLookup into text field

Posted on 2008-10-03
1
523 Views
Last Modified: 2012-05-05
Hi,
I am having problems tryiing to populate my text box with a field from a query. I have tried everything. Basically I want to be able to put a value in my text box, on my form, using the DLookup function. I am looking up values from my query and get a data type mismatch error. My query is;

SELECT tbl_Historical_SPN_Trades.spn_name, tbl_Exclusion_Type.Exclusion, tbl_Historical_SPN_Trades.Date_Added, tbl_Historical_SPN_Trades.spn_id AS SPN
FROM tbl_Historical_SPN_Trades INNER JOIN tbl_Exclusion_Type ON tbl_Historical_SPN_Trades.[Exclusion Type] = tbl_Exclusion_Type.Exclusion_ID;

And My DLookup is

strSPNValue = txtSPN.Value  (Which will equal something like 0020397)
txtExclusion.Text = DLookup("[Exclusion]", "Sel_Historical_SPN_Lookup", "SPN = " & strSPNValue)

Now SPN is a text field in my table, as is Exlusion. I can not see why the error is occuring?
0
Comment
Question by:andyb7901
1 Comment
 
LVL 84

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 500 total points
ID: 22632560
Text values must be enclosed in single or double quotes. I use single quotes:

txtExclusion = DLookup("[Exclusion]", "Sel_Historical_SPN_Lookup", "SPN ='" & strSPNValue & "'")

Also, don't set the .Text value ... in order to do that, your control must have the focus. Access isn't like other programming environments (like VB) ...
0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

912 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now