?
Solved

Access VBA get data into variable

Posted on 2007-11-28
3
Medium Priority
?
632 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 2000 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

719 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