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

  • Home
  • SEARCH
  • 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 382349
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T15:10:26+00:00 2026-05-12T15:10:26+00:00

I’m new to VBA and Access in general and ran into this problem whilst

  • 0

I’m new to VBA and Access in general and ran into this problem whilst trying to use the proposed alternate implementation from another question I’d asked (DLookup in Access not running until textBox clicked on in Form)

The code below runs, the issue is that Me.Key is different for each record being displayed in the form and running this in the form open event means it grabs only the first value assigned to Me.Key from the first record. How can i make this run so that Me.Key is different for each record/line being displayed?

Dim rs As DAO.Recordset
Dim db As Database
Dim qdf As QueryDef
Dim prm As Parameter

Set db = CurrentDb
Set qdf = db.QueryDefs("[MF INCOME - STREAM MONTHLY]")
For Each prm In qdf.Parameters
    prm.Value = Eval(prm.Name)
Next prm

Set rs = qdf.OpenRecordset(dbOpenDynaset)
rs.FindFirst "[MyMonth]=10 AND [Org_Type]='" & Me.Key & "'"
Me.Oct = rs!SumVal
'...other month assignments
  • 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-05-12T15:10:26+00:00Added an answer on May 12, 2026 at 3:10 pm

    I guess the Me.Key refers to a control located in the details section of your form. In this case, and in order to list all values taken by the control, you will need to browse all the records. One of the ways to do so can be:

    Dim m_position as Long
    for m_position = 1 to Me.recordset.recordcount
       me.seltop = m_position
       debug.print me.key
    next m_position
    

    Unfortunately your will see your screen blincker while browsing all the lines. You can off course find some ‘screenFreezer’ utilities for VBA on the net (there is one called LockWindowUpdate, as long as I can remember).

    Another solution is to browse the clone of the underlying recordset (browsing the recordset will provoke the same screen behaviour as before). Supposing that the Me.Key control is bound to the “Key” column of the recordset, code could be:

    Dim rsClone as DAO.recordset
    set rsClone = Me.recordsetclone
    if rsClone.EOF and rsClone.BOF then
    Else
        rsClone.moveFirst
        Do while not rsClone.EOF
            debug.print rsCLone.fields("Key")
            rsClone.moveNext
        Loop
    Endif
    set rsClone = nothing
    

    My favorite is the first one, with the “freeze”option added. Your code can manage the seltop and selheight values of the form. This means you can browse specifically records selected by users and/or, once all records browsed, go back to the original record selection.

    EDIT:

    Following @Ben’s comment, I shall add that if your “myControl” control is in the details section and is unbound, you then will not be able to manage one value per row. The control will have the same value for all lines when the form is displayed as “continuous”.

    If your “myControl” control is bound to the “myField” field of a recordset, any of the following codes will increment “myControl” control value and “myField” field value at the same time. You will be than able to have a different value on each row:

    Solution 1:

    Dim m_position as Long
    for m_position = 1 to Me.recordset.recordcount
       me.seltop = m_position
       me.controls("myControl") = m_position
    next m_position
    

    Solution 2:

    Dim rsClone as DAO.recordset, _
        i as long
    
    set rsClone = Me.recordsetclone
    if rsClone.EOF and rsClone.BOF then
    Else
        rsClone.moveFirst
        i = 1
        Do while not rsClone.EOF
            rsClone.fields("myField") = i
            rsClone.update
            rsClone.moveNext
            i = i+1
        Loop
    Endif
    set rsClone = nothing
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.