Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem Creating Field in New Table Defnition 2

Status
Not open for further replies.

bodmin

Technical User
Apr 1, 2004
98
GB
Hi guys,

I have created a new database, and a table that I am going to export data to, the problem I have is when I am creating the fields I keep getting a Type Mismatch error

Set fld = tdf.CreateField("ProductId", dbInteger)
tdf.Fields.Append fld

This is the code I have been using to create the field in the new database, anybody got any ideas why I keep getting this error message?

cheers in advance
 
the fld variable is Dimmed as a Field,

do I need to make specific types for each field I am going to create?
 
Hi

It would have, been better if you had shown the DIM statement,

I am guessing you are using a version of Access after 97, and you need to qualify the DIM so

Dim fld AS DAO.Field


Regards

Ken Reay
Freelance Solutions Developer
Boldon Information Systems Ltd
Website needs upgrading, but for now - UK
 
Thanks Ken the DAO prefix worked perfectly.

Just for anyone else's future reference here is the code used to create a new database and then export the contents of a table in the current database to the new one.




Dim strSql As String
Dim ws As Workspace
Dim db As DAO.Database
Dim LFilename As String
Dim tdf As DAO.TableDef
Dim fld As DAO.Field
Dim idx As DAO.Index

'Get default Workspace
Set ws = DBEngine.Workspaces(0)

'Path and file name for new mdb file
LFilename = "c:\"
FileDate = Now()
FileDate = Format(FileDate, "DDMMYY")
LFilename = LFilename & FileDate & ".mdb"

'Make sure there isn't already a file with the name of the new database
If Dir(LFilename) <> "" Then Kill LFilename

'Create a new mdb file
Set db = ws.CreateDatabase(LFilename, dbLangGeneral)

Set tdf = db.CreateTableDef("XMLMapping")

Set fld = tdf.CreateField("ProductId", dbInteger)
tdf.Fields.Append fld

Set fld = tdf.CreateField("OrigoVersion", dbText, 5)
tdf.Fields.Append fld

Set fld = tdf.CreateField("Type", dbText, 12)
tdf.Fields.Append fld

Set fld = tdf.CreateField("Content", dbMemo)
tdf.Fields.Append fld

Set fld = tdf.CreateField("Deleted", dbBoolean)
tdf.Fields.Append fld

Set fld = tdf.CreateField("ExportedDate", dbDate)
tdf.Fields.Append fld

Set fld = tdf.CreateField("ReleaseDate", dbDate)
tdf.Fields.Append fld

db.TableDefs.Append tdf

Set idx = tdf.CreateIndex("PrimaryKey")

Set fld = idx.CreateField("ProductId")

idx.Primary = True
idx.Unique = False

idx.Fields.Append fld
tdf.Indexes.Append idx

strSql = "Insert Into " & LFilename & ".XMLMapping Select * from Local_Txn_XMLMappingFiles;"
DoCmd.RunSQL strSql

db.Close
Set db = Nothing
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top