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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:30:46+00:00 2026-05-27T03:30:46+00:00

I’m having a problem with running a custom function within an Access database. Currently,

  • 0

I’m having a problem with running a custom function within an Access database. Currently, there’s a process in place to import new data, and assign a foreign key (ENTRY_ID) to -1 for all new rows. A separate process runs to change the -1 to the next number in an incremental sequence.

This is the function:

Public Function GetNextEntry(table As String) As Double
    Dim r As DAO.Recordset
    Dim i As Double

    Set r = CurrentDb.OpenRecordset("SELECT LAST_ENTRY_ID FROM LAST_ENTRY WHERE TABLE_NM='" & table & "';")
    If r.EOF Then
        GetNextEntry = -1
        Exit Function
    End If
    i = r![LAST_ENTRY_ID] + 1
    r.Edit
        r![LAST_ENTRY_ID] = i
    r.Update
    GetNextEntry = i
Exit Function
GetNextEntry_ERROR:
    GetNextEntry = -1
End Function

And this is an extremely simplified version of the query:

INSERT INTO DATA
SELECT GetNextEntry('DATA') AS ENTRY_ID, IMPORT.*
FROM IMPORT

What I expect to get back would look like

ENTRY_ID, NAME, NUMBER
1, 'account 1', '1234567'
2, 'account 1', '1234567'
3, 'account 1', '1234567'
4, 'account 1', '1234567'
5, 'account 1', '1234567'

But I’m actually getting

ENTRY_ID, NAME, NUMBER
1, 'account 1', '1234567'
1, 'account 1', '1234567'
1, 'account 1', '1234567'
1, 'account 1', '1234567'
1, 'account 1', '1234567'

It seems that the function if running only once for the entire group. I can force it to run multiple times by feeding it data from the resulting dataset, but then if I scroll through the data, it will rerun the function each time the row is redrawn to the screen.

This is my long winded way of asking if there’s a better way to accomplish what I’m after. I assume there must be, because this seems overly complicated.

  • 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-27T03:30:47+00:00Added an answer on May 27, 2026 at 3:30 am

    Access is being smart; it does not realize that your function returns a different
    value each time.

    Try redefining your function as:

    Public Function GetNextEntry(table As String, salt as integer) As Double
    

    And then

    INSERT INTO DATA
    SELECT GetNextEntry('DATA', IMPORT.SOMEINTEGERFIELD) AS ENTRY_ID, IMPORT.*
    FROM IMPORT
    

    This way Access will think they GetNextEntry depends on a value from import and will get a new value each time.

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

Sidebar

Related Questions

I am currently running into a problem where an element is coming back from
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I want use html5's new tag to play a wav file (currently only supported
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I need a function that will clean a strings' special characters. I do NOT
I want to construct a data frame in an Rcpp function, but when I
I'm having trouble keeping the paragraph square between the quote marks. In firefox 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.