Solved

Ms Access - DLookup into text field

Posted on 2008-10-03
1
551 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

751 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