Results 1 to 5 of 5
  1. #1
    GeorgeJ is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Dec 2014
    Posts
    67

    Where is the new table?

    I am just starting out. I created a database with nothing in it and trying to create a simple table. I run MainTest and don’t get an error. I go back into the Application window expecting to see the new table named “NewTable”. Its not there. What am I doing wrong?



    Option Compare Database
    Option Explicit

    Sub CreateTable()
    Dim tblNew As DAO.TableDef, DB As DAO.Database, Fld As DAO.Field
    Set DB = CurrentDb
    Set tblNew = DB.CreateTableDef("NewTable")
    Set Fld = tblNew.CreateField("Num1", dbLong)
    tblNew.Fields.Append Fld
    End Sub

    Sub MainTest()
    CreateTable
    End Sub






    Thanks in advance

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,954
    Why do you even need to use code to create a table? Why not just use the table designer? If I had to create a table I would use SQL MAKE Table or SELECT INTO action to accomplish.
    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.

  3. #3
    GeorgeJ is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Dec 2014
    Posts
    67
    The reason that I want to use code to create a table is that I want to be able to create a temporary table as part of larger program. My program should be able to create a table, fill its records from a created query on other tables, and use the new table on various forms, and then delete the table. I'm just learning to use VB with Access, so one of my first goals is to learn how to create tables from VB code.

  4. #4
    amrut is offline Expert
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2012
    Location
    Dubai
    Posts
    614
    Can you use temporary table ? You only delete/append records to it when required , easier than creating table/fields.

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,954
    As amrut said - a 'temp' table is a permanent table but the records are temporary. Just delete all records at beginning of procedure.

    CurrentDb.Execute "DELETE FROM tablename"

    Should not have a process that regularly modifies structure of database.
    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. Replies: 3
    Last Post: 06-28-2013, 01:59 PM
  2. Replies: 4
    Last Post: 08-30-2012, 07:58 PM
  3. Replies: 8
    Last Post: 03-22-2012, 08:48 AM
  4. Replies: 2
    Last Post: 08-01-2011, 11:35 PM
  5. Replies: 2
    Last Post: 10-27-2009, 07:09 AM

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