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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T13:14:37+00:00 2026-06-03T13:14:37+00:00

I have this small VBA script in an Access database. There are a number

  • 0

I have this small VBA script in an Access database. There are a number of field comparisons I would like to do. In other languages, I would be able to make an array of keys and then use a for..each loop in order to test each key. Something like this:

string[] myKeys = { "key1", "key2", "key3" };
foreach(string myKey in myKeys)
{
    if(myRecordset!myKey == myTable!myKey) DoSomething()
}

I tried this in VBA, but it gives me Run-time error ‘3265’: Item not found in this collection when using the following code:

For Each myKey In myKeys
    If Not IsNull(myR![myKey]) Then Me.Recordset![myKey] = myR![myKey]
Next myKey

Is what I am trying to do even possible in VBA?

  • 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-03T13:14:39+00:00Added an answer on June 3, 2026 at 1:14 pm

    If you want to reference the value of a field whose name is stored in your variable myKey, use this …

    myR.Fields(myKey)
    

    That will work whether your recordset is a DAO or ADO object.

    Error 3265, “Item not found in this collection”, isn’t a complaint about the array. It’s telling you your recordset has no field whose literal name is “myKey”. Perhaps this code will make it clearer. It works without error as written. Un-commenting either of the first 2 Debug.Print lines will trigger error 3265.

    Public Sub foo()
        Const myKey As String = "id"
        Dim db As DAO.Database
        Dim rs As DAO.Recordset
        Dim strSelect As String
        strSelect = "SELECT id FROM MyTable;"
        Set db = CurrentDb
        Set rs = db.OpenRecordset(strSelect)
        'Debug.Print rs![myKey]
        'Debug.Print rs!myKey
        Debug.Print rs.Fields(myKey)
        rs.Close
        Set rs = Nothing
        Set db = Nothing
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this small PHP script that takes a POST variable and writes it
I have this small script: <? header('Content-Type: text/javascript; charset=utf-8'); $s=L\u00e1szl\u00f3 M\u00e1rton; echo $s; ?>
I have this small script that sorts the content of a text file #
I have this small script that shows a caption for a img when it
I have this small app that loads plugin type components that other users can
I have this small script: http://jsfiddle.net/gmAjC/ <input name=n1 value=test> <br/><span></span> <br/> <span style=background-color:red>after input</span>
I have this small problem with jquery: I need to do something like this:
I have this small script that changes the background image with a fadein/out effect:
I have this small toggle script, which toggles a panel, a class and text.
I have this small jquery script that does not work if I remove the

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.