Beginner -How to create a table with VBA?

Leen

Registered User.
Local time
Today, 20:52
Joined
Mar 15, 2007
Messages
56
I'd like to create a table using the folowing subprocedure:

-----
Sub CreateTable()

Dim dbs As Database, tbl As TableDef, fld As Field

Set dbs = CurrentDb

Set tbl = dbs.CreateTableDef("Test")
Set fld = tbl.CreateField("test1", dbText)

tbl.Fields.Append fld
dbs.TableDefs.Append tbl
dbs.TableDefs.Refresh

End Sub
----

I typed the above vba in a module. But, How can I run this subprocedure?

After searching for an answer, I understand I need a function procedure to run a sub procedure. So I made the folowing procedure:

-----
Public Function MakeTable() As Boolean

CreateTable()

End Function
-----

However, Acces gives me a fault on this the "CreatTable()" appears in red. Can someone help me how to run the above sub procedure?

Thanks a lot!
Leen (beginner..)
 
Remove the brackets from CreateTable()

ie

CreateTable
 
Sub Procedure

You don't have to create a function to run a sub procedure. You can run it from the immediate window or just click on the "play" button from the Visual Basic editor. Or you can call it any number of ways. You can also use a data definition query to create a table and run it from the DoCmd.RunSQL command.
 

Users who are viewing this thread

Back
Top Bottom