Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8346119
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T06:54:27+00:00 2026-06-09T06:54:27+00:00

I have a table that contains data that I am trying to import into

  • 0

I have a table that contains data that I am trying to import into a spreadsheet control on a userform in vba/excel.

The results will be viewed by an end user, so I have set the value of the header cells on initialization as opposed the the column headings from the sql table.

My query looks something like this

Dim conn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim sConnString As String


sConnString = "Provider=SQLOLEDB;Data Source=mysource;Initial Catalog=mydatabase;User Id=myusername;Password=mypassword;QuotedID=No"
Set conn = New ADODB.Connection
Set rs = New ADODB.Recordset

conn.Open sConnString
Set rs = conn.Execute("SELECT * FROM WOFT_tbl_clients WHERE userid =  '" & UserId.Value & "';")
If Not rs.EOF Then
   ///////////////// 
   /something here!/ 
   ///////////////// 
Else
  MsgBox "Error: No records returned.", vbCritical
End If

If CBool(conn.State And adStateOpen) Then conn.Close
Set conn = Nothing
Set rs = Nothing

What I am trying to do is get the output of selected columns from the database and be able to feed them into whatever colomn I like on the spreadsheet control.

So in effect I would somehow like a loop that allows me to output the resultset of columns id, name and userid into the spreadsheet control starting from row 2. My database also contains many other columns which are not needed in this spreadsheet, but will be needed for another spreadsheet control on the same userform, some of which will appear on both.

What I would like to be able to do is have each column in its own recordset, so I could have something like ids stored in a id recordset which I could then use in column A in spreadsheet control 1, and colomn 6 in spreadsheet control 2?

I hope this makes sense! I am using Excel 2010

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T06:54:28+00:00Added an answer on June 9, 2026 at 6:54 am

    To have each data column from one table in an extra recordset would lead you to isolated data lists, which wouldn’t follow any logic of a relational database model. If the data indeed is isolated in the way, that id is a list, name is another list and so on, living in the same table, then – forgive me – your database model is quite bad.

    If you nevertheless want to get only certain columns from your SQL database, specify them in the SQL statement:

    SELECT id, name, userid FROM tablename WHERE anycondition ORDER BY name
    

    To loop through every record the recordset object returns, use a do-until loop like this. Don’t forget the MoveNext, or it may result in an endless loop.

    Do Until rs.EOF
        ... do anything you want with the record ...
    
        rs.MoveNext
    Loop
    

    I hope this is what you needed. Feel free to further explain, if I didn’t understand your needs correctly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say I have a table or 2 that contains data that will never or
I have a table that contains unfortuantely bad data and I'm trying to filter
I have a table that contains all the data about users . Users can
I have a table in Oracle that contains a field with the data type
I have the unfortunate task of having to import data from excel into a
I have a UIViewController that contains a UITableView. I'm trying to fill this table
I have a data table that contains a one-to-many self referential relationship: Plant {
I have a table that contains multiple dropdown menus for a list of profile
I have a table that contains the following columns: ID int, DISTANCE float, EVENT
I have a table that contains common entries in two columns. For Example: Column1

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.