1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Solved: MSAccess 2003 - Copy current fieldvalue to a new record.

Discussion in 'Business Applications' started by Koen_, Sep 1, 2009.

Thread Status:
Not open for further replies.
Advertisement
  1. Koen_

    Koen_ Thread Starter

    Joined:
    Sep 1, 2009
    Messages:
    2
    I am adding some extra functionalities to an existing MS Access 2003 database. I would like to have a button, that copies some of the values of the current record that is open in the form, and pastes it into a new record.

    So if I would have a field called 'year', with the value '2009', I would like to have this same value '2009' pasted into the same field in a new record (I would like a seperate 'new record' button for this, using VB).

    Anyone can help me in accomplishing this? Help is very much appreciated! (y)
     
  2. OBP

    OBP Trusted Advisor

    Joined:
    Mar 8, 2005
    Messages:
    19,840
    Koen, welcome to the Forum.
    The way to do this as to assign your current Field's value to a Variable, go to the new record and then assign the variable's value to the Field.
    So the the VBA Code would look like this

    Dim tempvalue as string
    tempvalue = me.year
    DoCmd.GoToRecord , , acNext
    me.year = tempvalue

    where year is the actual name of your Field, if the value in the Field is a real date you would need to use
    Dim tempvalue as Date.
     
  3. terabytecomputer

    terabytecomputer

    Joined:
    Apr 20, 2009
    Messages:
    94
    In the button click sub, do this:

    Dim rs as Recordset
    Set rs=me.recordset
    rs.addnew
    rs!year = textbox1.value 'assuming textbox1 contains the year value
    rs.update
    rs.close


    That should get you close to what you're after, methinks. I haven't tested the code, but I think it's right.
     
  4. terabytecomputer

    terabytecomputer

    Joined:
    Apr 20, 2009
    Messages:
    94
    or what OBP said whilst I was typing away.
     
  5. Koen_

    Koen_ Thread Starter

    Joined:
    Sep 1, 2009
    Messages:
    2
    Hi,

    Thanks a lot, this worked!

    I have basic MSAccess knowledge, but my programming skills are still a bit lacking. Your help is much appreciated! :)
     
  6. Sponsor

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/857324

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice