Solved

Ms Access - DLookup into text field

Posted on 2008-10-03
1
555 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 85

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

The Orion Papers

Are you interested in becoming an AWS Certified Solutions Architect?

Discover a new interactive way of training for the exam.

Question has a verified solution.

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

AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

623 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