Pages

Saturday, January 7, 2012

Create Table Using Dao

if You want to create a new table with fields .Snapshot below


Here is the code-


Sub create_table_using_dao()
Dim tbl As DAO.TableDef
Dim fld As DAO.Field
' Sales_Detail name of table
Set tbl = CurrentDb.CreateTableDef("Sales_Detail")
' add fields or column
With tbl
' set a field with auto number
Set fld = .CreateField("S_NO", dbLong)
fld.Attributes = dbAutoIncrField
.Fields.Append fld
.Fields.Append .CreateField("Rep_ID", dbText)
.Fields.Append .CreateField("Rep_Name", dbText)
.Fields.Append .CreateField("Location", dbText)
.Fields.Append .CreateField("Sales", dbLong)
End With
CurrentDb.TableDefs.Append tbl
RefreshDatabaseWindow
Set fld = Nothing
Set tdl = Nothing

End Sub

2 comments:

  1. Can u post a VBA code for excel, where i would need the names of the text files should be captured based on the path given by user in 1st sheet, and second sheet should help us in importing all the text files selected in text format....

    Note: 1st text file should copy column headings and the rest should ignore pasting column headings.....

    And we might have 8 to 15 columns in text files.

    ReplyDelete