Solved

Access VBA get data into variable

Posted on 2007-11-28
3
623 Views
Last Modified: 2012-08-13
I have a table "target_table" with 2 columns,.  I want to simply a value from the table into a VBA string variable.  The code below fails:

Dim ftest As String

ftest = DoCmd.RunSQL ("select target_name from target_files where datasource = 'directsales'")
MsgBox ftest

Thanks,
Vishalarya
0
Comment
Question by:vishalarya
[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
3 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 20371850
ftest = DLOOKUP("target_name", "target_files", "datasource = 'directsales'")
0
 

Author Comment

by:vishalarya
ID: 20371871
Nice.

0
 
LVL 75
ID: 20371874
RunSQL only applies to an Action query (Update, Append, Delete and Make Table) ... not a Select query. So, nothing would be returned with your statement.

Use the DLookup as Angel suggested.

mx
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
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.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

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