Creating fields in tdfNew

P

Pendragon

Access03/WinXP

This should be fairly straightforward, so not sure what I am missing.
Looking at the help example for .CreateField (from the Northwind DB), I am
following the same format:

Set db = CurrentDb
set tdfNew = db.CreateTableDef("zTempBillInfo")

{definition of recordset}
rs.MoveFirst
With tdfNew
.Fields.Append .CreateField("ContactID", vbNumber)
.Fields.Append .CreateField("GroupA", vbCurrency)
...
End With

The code is bombing on the first .Fields.Append with an error "Data Type
Conversion Error" (#3421).

Ideas/suggestions?

Thanks.
 
P

Pendragon

Okay, I figured out the problem. For each field I was naming, I needed to
add the following line prior to the Append:

set fldName = tdfNew.CreateField(....)

and then after each instance I needed to have the tdfNew.Fields.Append fldName

Also, I discovered that the field definition is vbLong and vbNumber.

Works like a charm.
 
D

Douglas J. Steele

With tdfNew
.Fields.Append .CreateField("ContactID", vbNumber)
.Fields.Append .CreateField("GroupA", vbCurrency)
...
End With

should work, but neither vbNumber or vbCurrency are valid (unless you've
declared them yourself). If ContactID is supposed to be a Long Integer, use
dbLong. Use dbCurrency for GroupA.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top