Programmatically Adding Counter Field to Table Using DAO

B

Bhagya

Hi,
I am trying to create a field that would Programmatically
Add Counter Field to Table Using DAO

I tried using the code provided by MSFT

when I try to compile it I have this error coming up

" User defined type - not defined"
At the line
Dim DB As Database, TDef As TableDef, Fld As Field

Can anyone help me out with this?

Thanks in advance

Bhagya







Function AddCounter(Vendor As String, VendorID As String)
As Integer
Dim DB As Database, TDef As TableDef, Fld As Field
Dim DB As d

' Get the current database.
Set DB = CurrentDb()
' Open the tabledef to which the counter field
will be added.
Set TDef = DB.TableDefs(Vendor)

' Create a new AutoNumber field of type LONG
' with the automatic increment attribute.
Set Fld = TDef.CreateField(VendorID, dbLong)
Fld.Attributes = dbAutoIncrField

' If you are using version 2.0, replace the
' two lines above with the following two lines.
' Set Fld = TDef.CreateField(VendorID, DB_LONG)
' Fld.Attributes = DB_AUTOINCRFIELD

' Trap for any errors.
On Error Resume Next

' Append the new field to the tabledef.
TDef.Fields.Append Fld

' Check to see if an error occurred.
If Err Then
AddCounter = False
Else
AddCounter = True
End If

DB.Close

End Function
 
T

Tim Ferguson

" User defined type - not defined"
At the line
Dim DB As Database, TDef As TableDef, Fld As Field

Can anyone help me out with this?

In the VB Editor, choose Tools | Relationships, find the entry for DAO 3.6
and select it. Either move it above the entry for ADO, or uncheck the entry
for ADO altogether.

HTH


Tim F
 

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