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 8215267
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T11:43:30+00:00 2026-06-07T11:43:30+00:00

I am trying to use ADO to access and read some things from an

  • 0

I am trying to use ADO to access and read some things from an Excel File. I understand how to get it open and do the SELECT * and put that into a Recordset Object. What I don’t understand is if I am select a group of info, how to access specific fields in that Recordset.

Code:

Private Sub SaveReq_Click()
' 
' Saves the current entry to the database
' Into the TABLE 'pr_req_table'
' 

' Open a connection to the database
dim data_base as Database
set data_base = OpenDatabase(CurrentProject.Path & "\test_database.accdb")

Sub InsertRecord()
Dim data_base As Database
Set data_base = OpenDatabase(CurrentProject.Path & "\test_database.accdb")

' Grab all information from form
' Add information to pr_req_table
Dim qd As QueryDef
Set qd = data_base.CreateQueryDef("")
qd.sql = "INSERT INTO pr_req_table(pr_no, pr_date, pr_owner, pr_link, pr_signed) " & _
    "values([p1],[p2],[p3],[p4],[p5])"
qd.Parameters("p1").Value = pr_num.Value
qd.Parameters("p2").Value = Format(pr_date.Value, "mm/dd/yyyy")
qd.Parameters("p3").Value = List22.Value
qd.Parameters("p4").Value = "Excel Copy #" & elec_copy.Value
qd.Parameters("p5").Value =  "Signed Copy #" & sign_copy.Value 
qd.Execute


' The following section reads from the elec_copy field's hyperlink
' It scans the Excel file for items it needs to include into the table
' It enters those cells into the TABLE 'items_needed_table'
'
' Slects row by row, and if the item has been marked TRUE, inserts
' That row into the TABLE 'items_needed_table'


' Open a connection to Excel
On Error Resume Next

Const adOpenStatic = 3
Const adLockOptimistic = 3
Const adCmdText = &H0001

Set objConnection = CreateObject("ADODB.Connection")

objConnection.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
    "Data Source=" & elec_copy.Value & ";" & _
    "Extended Properties=""Excel 8.0;HDR=Yes;"";"

' Decalre a RecordSet Object
Set objRecordSet = CreateObject("ADODB.Recordset")

' Grab all Rows in the Plain_VDR Sheet where 'needed' column == TRUE
objRecordset.Open "Select line_no, desc, weeks FROM [Plain_VDR$] Where needed = TRUE", _
    objConnection, adOpenStatic, adLockOptimistic, adCmdText

' Declare a loop counter for row?
Dim x as Integer
x = 0

' Write the information pulled, into the TABLE 'items_needed_table' in Access Database
Do Until objRecordset.EOF
        qd.sql = "INSERT INTO items_needed_table(pr_no, line_no, desc, weeks) " & _
        "Values([p1],[p2],[p3])"
        ' p1 was declared earlier in code, same value as before
        qd.Parameters("p2").Value = objRecorset.(ROW_X, "line_no")
        qd.Parameters("p3").Value = objRecordset.(ROW_X, "desc")
        qd.Parameters("p4").Value = objRecordset.(ROW_X, "weeks")
        qd.Execute
        x = x + 1
Loop

' Close Database connection
data_base.Close

End Sub

My main point of concern is the ‘Do Until’ loop section. Doubtful I can insert the entire selection, because ‘pr_no’ is not defined in the Excel file, but back in Access Database, so I think I will need to loop that command for each row in the Excel file.
What do I need to use to assign my parameters the values, per row and field, from the Recordset Object?

Thanks in advance for any help!

Nathan

  • 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-07T11:43:32+00:00Added an answer on June 7, 2026 at 11:43 am

    In your connection string, you have said HDR=Yes, which means that the first row of your range contains the names of your fields, so, very roughly:

    Do Until objRecordset.EOF
        qd.Sql = "INSERT INTO items_needed_table(pr_no, line_no, desc, weeks) " & _
        "Values([p1],[p2],[p3])"
        ' p1 was declared earlier in code, same value as before
        '**No it was not, the earlier stuff is mostly irrelevant
    
        qd.Parameters("p2").Value = objRecorset.Fields("line_no")
        qd.Parameters("p3").Value = objRecordset.Fields("desc")
        qd.Parameters("p4").Value = objRecordset.Fields("weeks")
        qd.Execute
        ''You are moving through a recordset, not a worksheet
        objRecordset.MoveNext
    Loop
    

    If this all that you are doing with the selection from Excel, it could be inserted with one query, because you are not changing pr_num.

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

Sidebar

Related Questions

I'm trying to use the Task-Parallel-Library to offload expensive ADO.NET database access from the
I'm trying to use: // this is a BreakHistory class from the ADO.NET Data
I'm trying use mod_rewrite to rewrite URLs from the following: http://www.site.com/one-two-file.php to http://www.site.com/one/two/file.php The
I'm experimenting some difficulties trying to use Connection String Builders (ADO.NET) within LINQ to
So, I'm trying to use ADO.NET to stream a file data stored in an
I'm trying to use ADO to create several tables at once, into MS Access.
I'm trying to use a view to create an ADO.NET entity using a view.
I am trying to use the solution given here -> C# ADO.NET: nulls and
I am trying to make use of DataAdapter, unfortunately stuck with straight ADO.Net, and
I'm trying to use an Oracle database with ado.net, and it is proving a

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.