Solved

Access VBA get data into variable

Posted on 2007-11-28
3
618 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
3 Comments
 
LVL 142

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

947 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now