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.

Can you create a table from a form in Access 2002?

Discussion in 'Business Applications' started by tori712, Jul 3, 2007.

Thread Status:
Not open for further replies.
  1. tori712

    tori712 Thread Starter

    Joined:
    Jul 3, 2007
    Messages:
    1
    Hello. I created a new database modeling a form in Access 2002 from another database program that I have, yet I have not added any tables yet. I have always created forms, using a wizard, from existing tables in Access, yet this time, because there was so much needed on the form, I have done it backwards and I would like to now create the tables for it.

    The problem is, either it doesn't seem to be possible, or I just can't find the way to do it.

    Can anyone help me???
     
  2. OBP

    OBP

    Joined:
    Mar 8, 2005
    Messages:
    19,895
    As far as I know there is no automatic way to create a Table from an Unbound Form.
    It could probably be done using VBA, but the amount of Programming involved is likely to be more than just creating it manually in design view.
    One way to help you create the Table manually would be to use the Access Documenter to print out the Design Specification of your Form.
    I am not sure that the way that you have gone about it is the is the best way though.
    By just creating a form to enter the data may lead you to put all the data in one Table when in fact it should be split up between related tables.
    I can help you if you think that you need it.
     
  3. Rollin_Again

    Rollin_Again

    Joined:
    Sep 4, 2003
    Messages:
    4,912
    Open the database and press ALT+F11 to open the VBA editor. Click TOOLS --> REFERENCES and set reference to Microsoft DAO objects 3.6 click OK. Next copy and paste the code below to your button click event or other form event of your choice. The example code below will create the table with two fields and then add one record to it. If you need more help please post your database and/or form and provide a detailed explaination of what you would like to happen.

    Code:
    Dim db As DAO.Database
    Dim rs As DAO.Recordset
    Dim tdfNew As TableDef
    Dim fldNew As Field
    
    '--- set a reference to the database
    Set db = CurrentDb
    
    '--- create the table
    Set tdfNew = db.CreateTableDef("MyNewTable")
    
    '--- add integer field
    Set fldNew = tdfNew.CreateField("MyNewIntField", dbInteger)
    '--- save the new field
    tdfNew.Fields.Append fldNew
    
    '--- add text field (length 20)
    Set fldNew = tdfNew.CreateField("MyNewTextField", dbText, 20)
    '--- save the new field
    tdfNew.Fields.Append fldNew
    
    '--- save the new table design
    db.TableDefs.Append tdfNew
    
    '---Initialize your recordset
    Set rs = CurrentDb.OpenRecordset("MyNewTable", dbOpenDynaset)
    ' Add New Record
    rs.AddNew
    rs.Fields(0).Value = 1
    rs.Fields(1).Value = "FirstRecord"
    rs.Update
    
    '--- Clear memory
    Set fldNew = Nothing
    Set tblNew = Nothing
    Set db = Nothing
    
    
    Regards,
    Rollin
     
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!

Loading...
Thread Status:
Not open for further replies.

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

  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