Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Ms Access - DLookup into text field

Posted on 2008-10-03
1
Medium Priority
?
563 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 2000 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

Not sure which OpenStack Certification to get?

So you’ve realized you might want to get certified in OpenStack, but you’re not sure what the benefits might be or even which one you should take. You know there are several certification courses you can choose from, but how do you know which one is right for you?

Question has a verified solution.

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

Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
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 …
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

715 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