Results 1 to 5 of 5
  1. #1
    Join Date
    May 2004
    Posts
    133

    Unanswered: newbie need simple advice on VBA of creating new records

    Assumed that on 'ABC' form I have a unbound list box consists all departments on my company and a 'Open' button. And I have 'DEF' (tabular) form (recordsource set to 'workingtime' table and this table have 'employeeid filed') with 'employeeid' control.

    I wish when I click on the 'Open' button of 'ABC' form, it will open 'DEF' form and 'DEF' form will create new records, writing employeeid to 'employeeid' control of each newly created record.

    Please help me. I need your help.
    many thanks

  2. #2
    Join Date
    Jan 2005
    Posts
    31
    In command button's Click event, write some VBA code that will open the DEF Form.

    In the Activate event of DEF, write the VBA code that will create new records.

  3. #3
    Join Date
    May 2004
    Posts
    133
    many thanks for your guide. One more question:
    as I mentioned above, what command I will use to create multiple record on same time.
    If Ok, could you rwite more detail about how to create multiple records on samte time.
    many thanks

  4. #4
    Join Date
    Jan 2005
    Posts
    31
    Air Code (for creating multiple records at time):

    dim db as DAO.Database
    dim rs as DAO.Recordset
    dim strSQL as String

    strSQL = "SELECT Y1.Column1 FROM YourTable1 AS Y1"

    set db = currentdb()
    set rs = db.openrecordset(strSQL)

    rs.addnew
    rs.fields("Column1").value = "Whatever1"
    rs.update
    rs.addnew
    rs.fields("Column1").value = "Whatever2"
    rs.update

    rs.close
    set rs = nothing
    db.close
    set db = nothing


    Put the addnew/update segment inside a loop for lots of repeats.

    Use With blocks to save on typing rs over and over again (and for speed).
    Last edited by chris_n_osborne; 02-04-05 at 01:46.

  5. #5
    Join Date
    May 2004
    Posts
    133
    many thanks. You are greate helper for me. that what I'm looking for.
    thanks again

Posting Permissions

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