Results 1 to 11 of 11
  1. #1
    Aprilhm14 is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Dec 2013
    Posts
    8

    Automating records into a table

    I am trying to automate records into an existing table using vba.
    Is it necessary to create a form or a command... Can I just create a module and execute it?



    I just want to create a while loop that will automate the primary key field. For example record 1 pk is record1 record2 pk is record2 and keep the other fields the same.

  2. #2
    ranman256's Avatar
    ranman256 is online now VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,549
    Code:
    FOR i = 1 to 99
      vNdx = "Record" & i
      sSql = "insert into tbl ([id]) values ('" & vNdx & "')"
      docmd.runsql sSql
    next

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,597
    Yes, you can create a module and execute it. But how do you want to execute it - the Run tool on VBA editor menu?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  4. #4
    Aprilhm14 is offline Novice
    Windows 7 32bit Access 2010 64bit
    Join Date
    Dec 2013
    Posts
    8
    Quote Originally Posted by June7 View Post
    Yes, you can create a module and execute it. But how do you want to execute it - the Run tool on VBA editor menu?

    The easiest way. I am going to have change the format for the primary key a few different times for different records.. So a way that will make it easier to edit the text.

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,597
    What??? Change format for primary key???

    Do you have enough info to do what you want?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  6. #6
    Aprilhm14 is offline Novice
    Windows 7 32bit Access 2010 64bit
    Join Date
    Dec 2013
    Posts
    8
    Quote Originally Posted by June7 View Post
    What??? Change format for primary key???

    Do you have enough info to do what you want?

    My primary key is text.
    I want to automate records by just changing the primary key. Example of the primary key would be :

    mytextn , n<200


    mytext001
    mytext002
    mytext003
    mytext004 etc.

    Mytext might will change depending on the group of records

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,597
    Generating unique identifier is a common topic in forum. Here is a recent thread https://www.accessforums.net/program...not-44704.html

    However, since you want the text prefix to be different for some condition, will need more complicated VBA code that will find the max value for the condition.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  8. #8
    Aprilhm14 is offline Novice
    Windows 7 32bit Access 2010 64bit
    Join Date
    Dec 2013
    Posts
    8
    I am lost at how to even start. Is it necessary to create a form or a command... Can I just create a module and execute it?

  9. #9
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,597
    Yes, you can just create a general module and execute it from the VBA menu bar.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  10. #10
    Aprilhm14 is offline Novice
    Windows 7 32bit Access 2010 64bit
    Join Date
    Dec 2013
    Posts
    8
    Thanks! I got it to work. I still had to make a button. Is there a way to turn off the message " You are about to append one row" ?

  11. #11
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,597
    Use:

    CurrentDb.Execute strSQL
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Automating a process with a form
    By Topper in forum Forms
    Replies: 2
    Last Post: 06-12-2013, 09:14 AM
  2. Automating import and export
    By trotta in forum Access
    Replies: 4
    Last Post: 02-19-2013, 06:51 AM
  3. Replies: 1
    Last Post: 02-08-2012, 04:50 PM
  4. automating data entry
    By phineas629 in forum Programming
    Replies: 2
    Last Post: 10-26-2011, 01:04 PM
  5. Automating Reports
    By Christopher in forum Import/Export Data
    Replies: 3
    Last Post: 04-22-2010, 01:40 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums