+ Reply to Thread
Results 1 to 3 of 3

checking for the existence of a record in a spreadsheet from a user form

  1. #1
    Registered User
    Join Date
    01-06-2020
    Location
    Vancouver, Canada
    MS-Off Ver
    10
    Posts
    39

    checking for the existence of a record in a spreadsheet from a user form

    I have a form (MyForm) for users to input data (two key fields they enter in the form are DATE and LOCATION). Then when they click a MySave button on MyForm, the data they entered in the form is saved to individual columns the next blank row in a spreadsheet.

    I want to make sure that they cannot save a record that has the exact same DATE and LOCATION as a record that had already been saved in the spreadsheet.

    So I'm looking for some code that I can have on the click event for MySave that first checks the spreadsheet to ensure a record with the same date in the DATE column and the same location in the LOCATION column does not exist. If such a record already exists, then a msgbox appears telling the user that the record already exists.

  2. #2
    Forum Expert
    Join Date
    10-06-2017
    Location
    drevni ruchadlo
    MS-Off Ver
    old
    Posts
    2,150

    Re: checking for the existence of a record in a spreadsheet from a user form

    Maybe a small sample xls file with the correct data layout and your coding ?

  3. #3
    Registered User
    Join Date
    03-18-2020
    Location
    India
    MS-Off Ver
    2016
    Posts
    7

    Re: checking for the existence of a record in a spreadsheet from a user form

    Basically, you do not want a duplicate record.

    This is a simple workaround needs a little setup but saves a lot of coding. I use a simple method to check for duplicates. Usually, all my workbooks have a calculation sheet, In the calculation sheet, I look up the text box value if an error is returned I proceed to save the file if the lookup returned a value that means there already is a record. So a message is displayed.

    If your case I will do the following:
    In the calculation sheet, I will have two cells A1, A2. I will store Date in A1 and Location in A2. In b1 and B2, I will write a formula to lookup values in A1 and A2 from the dataset. In B3 I will write an OR function to check if either b1,b2 returns an error that means the combination of date and location does not exist in the database. If none of them returns an error that means the combination exists.

    I can share a worksheet with example if this is not clear.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. User form add record
    By Bennasy23 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 05-14-2020, 06:22 AM
  2. [SOLVED] checking two dates on user form
    By tomanton in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-04-2014, 08:23 AM
  3. For Loop Problem when checking for File Existence
    By kopite2002 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-03-2011, 03:26 PM
  4. Checking for User Form loaded
    By scottintexas in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-21-2008, 02:58 AM
  5. Checking for existence of worksheet before creating
    By Marc Gendron in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-13-2006, 02:45 PM
  6. Checking for the existence of a characted in a string
    By Peter Rooney in forum Excel General
    Replies: 2
    Last Post: 06-21-2006, 05:20 AM
  7. [SOLVED] Checking the existence of a reference workbook
    By Frederick Chow in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-05-2006, 03:50 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1