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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T18:14:55+00:00 2026-06-14T18:14:55+00:00

I have created a custom function that is used in a query. The function

  • 0

I have created a custom function that is used in a query. The function opens a small table (50 cells) and adds a date to one column in the query based on lookup results. The function performs too slowly though and I think it may be because I open and close the record set for every record in the query. Is there a way to avoid opening the record set and closing it every time the function is called? I suspect this defeats the purpose of using a function in the first place but am hoping someone has a solution.

Added after original post.

Based on the structures below, I need to get the Description from the table into the CustomFunctionField in the query and the date fields are the connection. The table holds the date range and the query has specific dates in the date range.

–Query–
ID | Info | Date | CustomFunctionField

–Table–
ID | StartDate | EndDate | Description

Following is the code:

Public Function SelectTerm(DateFull)

    Dim rstin As DAO.Recordset
    Dim dx As Date
    Dim dterm As String

    Set rstin = CurrentDb.OpenRecordset("tblTerms", dbOpenSnapshot)

    dx = "1/1/2000"

    If Not rstin.EOF And Not rstin.BOF Then
        Do Until rstin.EOF Or dx >= DateFull
            dx = rstin.Fields("DateEnd")
            rstin.MoveNext
        Loop

        rstin.MovePrevious
        dterm = rstin.Fields("Description")
        rstin.Close
    End If

    SelectTerm = dterm

End Function
  • 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-14T18:14:56+00:00Added an answer on June 14, 2026 at 6:14 pm

    Use a correlated subquery to look up the term description from tblTerms based on a Date/Time field, DateFull, in your main table.

    SELECT
        y.DateFull,
        (
            SELECT TOP 1 [Description]
            FROM tblTerms
            WHERE DateEnd <= y.DateFull
            ORDER BY DateEnd DESC
        ) AS term_description
    FROM YourTable AS y;
    

    Correlated subqueries aren’t exactly known for blazing performance. However, this approach should be much faster than a UDF which opens a recordset and moves through the rows until it finds the value you want.

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

Sidebar

Related Questions

I have created a custom function and I am getting this error. I dont
I have created custom posts and I want one page in my site to
I have created a custom cell for loading into a table. The interface is
I have created a custom method that will return unique items, together with the
I have created custom registration form in drupal 6. i have used changed the
I have created a custom control using VB.NET in Visual Studio 2008 that gives
I have created a jQuery plugin that is used to create html on a
I have created custom jQuery UI widget called uiPopover, very similar to UI-dialog (in
I have created custom cell in which there are n number of image views.
friends, i have created custom title bar using following titlebar.xml file with code <?xml

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.