Solved

Access VBA get data into variable

Posted on 2007-11-28
3
617 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
Comment Utility
ftest = DLOOKUP("target_name", "target_files", "datasource = 'directsales'")
0
 

Author Comment

by:vishalarya
Comment Utility
Nice.

0
 
LVL 75

Expert Comment

by:DatabaseMX (Joe Anderson - Access MVP)
Comment Utility
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
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…

743 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

18 Experts available now in Live!

Get 1:1 Help Now