[AccessD] Problem with code to change field data type in vba

Paul Black pblack at hotmail.com
Tue Sep 14 17:16:40 CDT 2004


Hi

I using Access 97 and can not get the following to work:

Private Sub Command0_Click()
Dim fld As Field
Dim dbs As Database
Dim tbl As TableDef

Set dbs = CurrentDb()
For Each fld In tbl.Fields
    If Left$(tbl.Name, 2) = "t_" And fld <> "t_proj" And fld <> "t_pt" And 
fld <> "t_plink" And fld <> "ptlink" And fld <> "t_species" Then
        fld.Type = dbInteger
    End If
Next fld

Beep
MsgBox "Done"
End Sub

It is supposed to change the field data type to integer from text. All field 
names to change begin with 't_' excluding certain fields listed above. I 
keep getting an error:

Runtime error '91'
Object Variable or With Block variable not set

Other than the excluded fields above all the data conatined in the fields is 
numeric or has a Null value... but it is in a text field. The data is coming 
to me off of a Pocket PC and it won't let me change the field type to 
numeric.

Please help me solve this.

Thanks

PB

_________________________________________________________________
Get ready for school! Find articles, homework help and more in the Back to 
School Guide! http://special.msn.com/network/04backtoschool.armx




More information about the AccessD mailing list