Getting started with VB in access


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Getting started with VB in access

  1. #1
    JD Guest

    Getting started with VB in access


    This is a very elementary question, i am a VB coder , but not in Access (yet).
    I would like to write code that will trigger on an Access form (I put a
    cmd button on and in the properties under events, onClick, i wrote an event
    procedure). I get the event to trigger (just sent a MsgBox "Hi" thing) .
    What I would like to do is have the user at the last record on the form,
    press this new cmd button and the entire record is copied to the next record
    ( a new record). THe person using this database table (of which the form
    is based) is trying to eliminate copying redundant data by hand. He knows
    (as well as I that the database is not normalized right now and will be later
    down the road). I also successfully am reading all the data from the form
    (Me!nameofcontrol) and taking the primary key and changing it to a new, unique
    value. WHAT I CANNOT figure out how to do is:
    add a new record via code, to fill in this data (new key data and copy of
    old other fields). I wondered if there was a DoCmd RunCommand I could use?

    Otherwise, do I need to make a different kind of module , an use DAO to set
    a recordset , etc and do methods on it?

    Help if you can. I appreciate it!!!

  2. #2
    Ian King Guest

    Re: Getting started with VB in access

    Hi JD

    Do this

    With Me.RecordsetClone
    .AddNew
    .Fields(0) = "<whatever 0>" ' or Fields("name of field") =
    .Fields(1) = "<whatever 1>"
    .Fields(2) = 1234
    .Fields(3) = "This is a test"
    .Update
    End With
    Me.Refresh


    regards

    Ian

    ** invalid email address, change dk to denmark

    homepage http://www.kingsoft-denmark.com/


    JD <jdonahue@ee.net> wrote in message news:390af5a6$1@news.devx.com...
    >
    > This is a very elementary question, i am a VB coder , but not in Access

    (yet).
    > I would like to write code that will trigger on an Access form (I put a
    > cmd button on and in the properties under events, onClick, i wrote an

    event
    > procedure). I get the event to trigger (just sent a MsgBox "Hi" thing) .
    > What I would like to do is have the user at the last record on the form,
    > press this new cmd button and the entire record is copied to the next

    record
    > ( a new record). THe person using this database table (of which the form
    > is based) is trying to eliminate copying redundant data by hand. He knows
    > (as well as I that the database is not normalized right now and will be

    later
    > down the road). I also successfully am reading all the data from the form
    > (Me!nameofcontrol) and taking the primary key and changing it to a new,

    unique
    > value. WHAT I CANNOT figure out how to do is:
    > add a new record via code, to fill in this data (new key data and copy of
    > old other fields). I wondered if there was a DoCmd RunCommand I could use?
    >
    > Otherwise, do I need to make a different kind of module , an use DAO to

    set
    > a recordset , etc and do methods on it?
    >
    > Help if you can. I appreciate it!!!




  3. #3
    Nick Guest

    Re: Getting started with VB in access


    JD,

    Following is a VB function that takes a number of variables and uses them
    to add a new row to an Access db. In you VB program, you'll also need to
    set a reference to the DAO 3.51 library.

    Let me know if you need help setting up the code to open your database and
    recordset.

    Nick

    Function AddName(rstTemp As Recordset, _
    xname As String, xcap As String, xmembernumber As String)

    With rstTemp
    .AddNew
    !Membername = xname
    !handicap = xcap
    !MemberNumber = xmembernumber
    .Update
    End With
    End Function


    "JD" <jdonahue@ee.net> wrote:
    >
    >This is a very elementary question, i am a VB coder , but not in Access

    (yet).
    > I would like to write code that will trigger on an Access form (I put a
    >cmd button on and in the properties under events, onClick, i wrote an event
    >procedure). I get the event to trigger (just sent a MsgBox "Hi" thing) .
    >What I would like to do is have the user at the last record on the form,
    >press this new cmd button and the entire record is copied to the next record
    >( a new record). THe person using this database table (of which the form
    >is based) is trying to eliminate copying redundant data by hand. He knows
    >(as well as I that the database is not normalized right now and will be

    later
    >down the road). I also successfully am reading all the data from the form
    >(Me!nameofcontrol) and taking the primary key and changing it to a new,

    unique
    >value. WHAT I CANNOT figure out how to do is:
    >add a new record via code, to fill in this data (new key data and copy of
    >old other fields). I wondered if there was a DoCmd RunCommand I could use?
    >
    >Otherwise, do I need to make a different kind of module , an use DAO to

    set
    >a recordset , etc and do methods on it?
    >
    >Help if you can. I appreciate it!!!



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center