+ Reply to Thread
Results 1 to 7 of 7

Transfer data to Access database but only if a value doesn't exist in a table and field

  1. #1
    Registered User
    Join Date
    01-02-2021
    Location
    Netherlands
    MS-Off Ver
    2013
    Posts
    3

    Transfer data to Access database but only if a value doesn't exist in a table and field

    I hope someone can help me out. I just recently started to work with VBA. I'am trying to build a UserForm where a user can fill in the form and after that it generates a document/report.
    That seems to work out well.

    I also want to transfer the data that is entered into a access database. But.... If the information in a certain TextBox matches a number in table1, field1 (or colomn, i named it var1) i want to
    edit that specific record instead of creating a new record (in the Access Database). If the information in the textbox doesn't match with the number in table 1, field1, then it has to add a new record.

    I know that I can edit a record with .edit and that i can add an new record with : AddNew.

    I used Microsoft Word with VBA to build the userform. I can't find any good forum specific for MS Word so I hope someone here can help me out. Thanks for the effort.

    To be more specific, what I want it to do:

    If the value in the textbox already is in the table
    Edit record in the table in access
    Else value in textbox is not there
    Insert a new record
    End If

    Script:

    Please Login or Register  to view this content.
    Last edited by AliGW; 01-03-2021 at 07:56 AM.

  2. #2
    Registered User
    Join Date
    01-02-2021
    Location
    Netherlands
    MS-Off Ver
    2013
    Posts
    3

    Re: Transfer data to Access database but only if a value doesn't exist in a table and fiel

    Solved. This topic can be closed.

  3. #3
    Forum Contributor
    Join Date
    06-02-2019
    Location
    libya
    MS-Off Ver
    2010
    Posts
    734

    Re: Transfer data to Access database but only if a value doesn't exist in a table and fiel

    hi Wouter , I hope to share the solution with the members what see your post may be somebody has the same problem finds the solution in your post , and mark solved this post to take advantage
    thanks
    Last edited by ABDELFATTA; 01-03-2021 at 04:41 AM.

  4. #4
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,916

    Re: Transfer data to Access database but only if a value doesn't exist in a table and fiel

    Yeas, I'm curious too, we all learn from what others solved
    ---
    Hans
    "IT" Always crosses your path!
    May the (vba) code be with you... if it isn't; start debugging!
    If you like my answer, Click the * below to say thank-you

  5. #5
    Registered User
    Join Date
    01-02-2021
    Location
    Netherlands
    MS-Off Ver
    2013
    Posts
    3

    Re: Transfer data to Access database but only if a value doesn't exist in a table and fiel

    Ok. I was trying and I didn't seem to work. So I found out about ".FindFirst".
    FindFirst didn't seem to work either until I changed the specific field in the database (the column that I use as reference to see of the value already is in the database) to nummeric.

    Then I changed the code like this: (The value in textbox20 is used as reference to the database. If the number already exists the file updates, otherwise it makes a new record.

    Couldn't find it anywhere on the internet. With my knowledge of VBA (+/- 1 week) I don't think it's the best way to solve the problem. But... for now, it works out just fine.

    Hope anyone can use it. If anyone got tips to improve it, please let me know !

    -----------------------------
    Code
    -----------------------------

    Please Login or Register  to view this content.
    Last edited by AliGW; 01-03-2021 at 07:56 AM.

  6. #6
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2406 (Windows 11 23H2 64-bit)
    Posts
    82,813

    Re: Transfer data to Access database but only if a value doesn't exist in a table and fiel

    Administrative Note:

    Welcome to the forum.

    We would very much like to help you with your query, however you need to include code tags around your code.

    Please take a moment to add the tags. Posting code between tags makes your code much easier to read and copy for testing, and it also maintains VBA formatting.

    Please see Forum Rule #2 about code tags and adjust accordingly. Click on Edit to open your post, then highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here

    (Note: this change is not optional. As you are new, I will do it for you this time.)

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  7. #7
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,670

    Re: Transfer data to Access database but only if a value doesn't exist in a table and fiel

    deleted
    Missed
    it works out just fine.
    Last edited by jindon; 01-03-2021 at 08:05 AM.

+ 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. Replies: 0
    Last Post: 03-10-2013, 04:19 PM
  2. Replies: 9
    Last Post: 05-22-2012, 08:59 AM
  3. Add Blank Records (which doesn't exist) in Access Report
    By BlastRanger in forum Access Programming / VBA / Macros
    Replies: 0
    Last Post: 04-25-2012, 05:05 AM
  4. VBA to transfer Excel data to an Access table
    By beckajayne in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 10-18-2011, 03:00 PM
  5. Transfer data from excelsheet to access table
    By aman1234 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-16-2011, 04:35 AM
  6. Transfer data from Access table to Excelsheet
    By aman1234 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-27-2010, 03:38 AM
  7. Get data from an access database table
    By GWB in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-23-2010, 02:41 PM
  8. excel transfer data to access table
    By nominoo in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 01-26-2010, 02:30 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