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
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