[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Return Select query result to string variable in Access 2007

Posted on 2011-02-15
5
Medium Priority
?
1,742 Views
Last Modified: 2012-05-11
I need to be able to run a SELECT query and return all values it finds to a string variable with the results seperated by commas using VBA. Can anyone help?
0
Comment
Question by:JP_TechGroup
[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
5 Comments
 
LVL 60

Accepted Solution

by:
HainKurt earned 1000 total points
ID: 34901471
get the result as is from db and concatenate in the app

rs = cmd.open(sql)
whil not rs.eof
  if s="" then s = s & ", "& rs(0)
  if s<>"" then s = s & ", "& rs(0)
wend
0
 
LVL 52

Assisted Solution

by:Gustav Brock
Gustav Brock earned 1000 total points
ID: 34904751
I would use GetRows.
From the on-line help:
Sub RækkerMatrix()
  Dim dbs As Database, rst As Recordset, strSQL As String
  Dim varRecords As Variant, intI As Integer, intJ As Integer

  Set dbs = CurrentDb
  strSQL = "SELECT * FROM tblYourTable"
  Set rst = dbs.OpenRecordset(strSQL)
  rst.MoveLast
  rst.MoveFirst
  varRecords = rst.GetRows(rst.RecordCount)
  For intI = 0 To UBound(varRecords, 2)
    Debug.Print
    For intJ = 0 To UBound(varRecords, 1)
      Debug.Print varRecords(intJ, intI)
    Next intJ
  Next intI
  rst.Close
  Set dbs = Nothing
End Sub

Open in new window


Adjust the line
      Debug.Print varRecords(intJ, intI)
to fit your need.

/gustav
0
 
LVL 26

Expert Comment

by:EDDYKT
ID: 34906061
0
 
LVL 1

Author Closing Comment

by:JP_TechGroup
ID: 34908329
Used data gathering from one and string handling for the other. Thanks guys.
0
 
LVL 52

Expert Comment

by:Gustav Brock
ID: 34908404
You are welcome!

/gustav
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Make the most of your online learning experience.
Instead of error trapping or hard-coding for non-updateable fields when using QODBC, let VBA automatically disable them when forms open. This way, users can view but not change the data. Part 1 explained how to use schema tables to do this. Part 2 h…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Suggested Courses

649 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