Access macro not working?
I created a function in a module:
Public Function createTable()
Dim db As Database
Dim tdf As TableDef
Dim fld As Field
Set db = CurrentDb()
Set tdf = db.CreateTableDef("161-0363")
Set fld = tdf.CreateField("SKUS", dbText, 30)
tdf.Fields.Append fld
Set fld = tdf.CreateField("Count", dbInteger)
tdf.Fields.Append fld
End F开发者_开发技巧unction
Then called this function in a macro using "RunCode". But no table is created when I run the macro? Can anyone help me out?
Thanks!
On your Macro Design View, you should have it say RunCode
, then in your Function Name
it should say createTable()
Does the code create a table if you run it without a macro?
EDIT: Update your code to this then run your macro
Public Function createTable()
Dim db As DAO.Database
Dim tdf As DAO.TableDef
Dim fld As Field
Set db = CurrentDb()
Set tdf = db.CreateTableDef("161-0363")
Set fld = tdf.CreateField("SKUS", dbText, 30)
tdf.Fields.Append fld
Set fld = tdf.CreateField("Count", dbInteger)
tdf.Fields.Append fld
db.TableDefs.Append tdf
db.TableDefs.Refresh
End Function
I just tested the above code and it created the table. You needed to add the last lines of code to get it to work.
精彩评论