table has wrong data type

E

Eric

Hello. I am wondering if it's possible to change a fields
data type via VBA? The reason I am asking is I have a make
table query (tmpGloss10Week2 is the table name) that the
field called PCTAcceptable is a text field instead of a
Number data type field. I have tried the following code
with no success:

Sub ChangeDataType()

Dim dbs As DAO.Database
Dim tbl As TableDef
Dim fld As Field

Set dbs = CurrentDb
Set tbl = dbs.TableDefs("tmpGloss10Week2")
Set fld = tbl.Fields("PCTAcceptable")

fld.Attributes = dbFixedField

End Sub

What am I missing?
 
A

Andi Mayer

Hello. I am wondering if it's possible to change a fields
data type via VBA? The reason I am asking is I have a make
table query (tmpGloss10Week2 is the table name) that the
field called PCTAcceptable is a text field instead of a
Number data type field. I have tried the following code
with no success:

Sub ChangeDataType()

Dim dbs As DAO.Database
Dim tbl As TableDef
Dim fld As Field

Set dbs = CurrentDb
Set tbl = dbs.TableDefs("tmpGloss10Week2")
Set fld = tbl.Fields("PCTAcceptable")

fld.Attributes = dbFixedField

End Sub

What am I missing?

look at the SQL help under
ALTER TABLE mytable ALTER COLUMN
 
T

Tim Ferguson

The reason I am asking is I have a make
table query (tmpGloss10Week2 is the table name) that the
field called PCTAcceptable is a text field instead of a
Number data type field

If the tmp prefix means it's temporary table, then you could (a) fix the
code that created it, so that future tables would be correct, and (b) use
a query to cast the text into a number for the time being...

SELECT ALL GlossID, CInt(WeekNo) AS WeekNumber, SomethingElse
FROM tmpGloss10Week2

etc

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