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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T04:55:15+00:00 2026-06-18T04:55:15+00:00

Setup: I am creating an ms access database to record the results of experiments

  • 0

Setup: I am creating an ms access database to record the results of experiments that will be done by myself and others. I have created a form and a subform; the main form contains fields about the equipment setup and the subform contains the experiments with that equipment setup. The link master and link child are the SettingID.

Problem: Even though the fields in the main [settings] form are limited to combo-box selections, there are still numerous setting combinations. Therefore when the user is entering information into the form, they may not realize that a record with the same settings already exist and since the SettingID is an autonumber it will appear to be a unique record when in reality it isn’t.

Question: I would like to run a query on the BeforeInsert event to check if a record with the same settings exist before creating this record. If the record doesn’t exist, then proceed as normal; if it does exist, then alert the user and bring them to that record. I am at a loss as to how to accomplish this. What I have tried so far to do this isn’t worth mentioning but I am continuing to try and figure something out until someone answers this post.

  • 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-18T04:55:17+00:00Added an answer on June 18, 2026 at 4:55 am

    I believe you’ll want two things, depending on how user-friendly you want the interface.

    Unique Index

    Add a multi-column unique index on the columns in the Settings table in which their combination of values you don’t ever want to be duplicated in another row. Can read how in the link provided by KFleschner in the comments to your original post, or check out the second answer of this question which has a screenshot to go along with the steps: Can we create multicolumn unique indexes on MS access databases?. This will disallow duplicates in the Settings table.

    For instance, if your settings and experiments were for computer rigs and you had a Settings table with the following columns:

    SettingID, RAM_GB, CPU_GHz

    Then your primary key would be (SettingID) and your multi-column unique index would be on (RAM_GB, CPU_GHz), because you only want one record with the same RAM capacity and CPU speed.

    In database language, your primary key, SettingID, will be what is known as a surrogate key. And the new multi-column unique index will be what is known as a natural key. Both can be used to identify a unique row, but the primary key (the surrogate key) is what is used in any foreign key relationships, such as SettingID in your Experiments table.

    This by itself will prevent the duplicate issue, since it will be enforced at the database level. However, it won’t automatically make your form jump to the record with a matching natural key. Instead Access will alert the user with a message along the lines of you’ve entered a record that violated an index. But nothing more. The user will have to cancel out of the new record and go find the matching one himself.

    Before Update Event

    The Before Insert event triggers upon the first character of input for a new record. See http://msdn.microsoft.com/en-us/library/office/ff835397.aspx for details. This is too soon, you want the Before Update event. And add code to the event like this:

    Private Sub Form_BeforeUpdate(Cancel As Integer)
        Set rst = Me.RecordsetClone
        rst.FindFirst "[SettingID] <> " & Me.SettingID & " AND [RAM_GB] = " & Me.RAM_GB & " AND [CPU_GHz] = " & Me.CPU_GHz
        If Not rst.NoMatch Then
            Cancel = True
            If MsgBox("Setting already exist; goto existing record?", vbYesNo) = vbYes Then
                Me.Undo
                DoCmd.SearchForRecord , , acFirst, "[SettingID] = " & rst("SettingID")
            End If
        End If
        rst.Close
    End Sub
    

    This code assume a few things:

    1. [RAM_GB] and [CPU_GHz] are the columns of your multi-column unique index.
    2. [SettingID] is the column in your primary key.

    Tweak the column names and such to your needs and then you’ll also have a way to prompt and auto-navigate to the existing record.

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

Sidebar

Related Questions

I have a Setup Project that is creating an installation for an extension of
I am just learning Access and have been tasked with creating a database for
The basic setup is classic - you're creating a Windows Forms application that connects
I'm creating an Access 2010 database to replace an old Paradox one. Just now
We have a BI team that have created a wonderful data warehouse that works
Setup: I have two trees of scripts that run on Oracle 11g - one
I am in the process of rewriting an Access database and I have some
I have an MEMORY MYSQL database that contains a table with 200k+ rows. I
I have a form that creates a new brand. The user chooses a name,
I am currently using PHP PDO to access my database. That is all working

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.