Solved

Access VBA get data into variable

Posted on 2007-11-28
3
620 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 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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
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…
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…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

828 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