Format - Fixed property (1 Viewer)

aziz rasul

Active member
Local time
Today, 22:58
Joined
Jun 26, 2000
Messages
1,935
I have the following code: -

Code:
CurrentDb.Execute "ALTER TABLE tblTemp ALTER COLUMN MedianValue Double;"

How do I add to this so that the Format property is set to 'Fixed'?
 

DJkarl

Registered User.
Local time
Today, 16:58
Joined
Mar 16, 2007
Messages
1,028
I don't think you can set the format property of a table in Access via SQL. If you are already running VBA code you should be able to set the properties using a tabledef object.
 

aziz rasul

Active member
Local time
Today, 22:58
Joined
Jun 26, 2000
Messages
1,935
OK I'll look into that.
 

aziz rasul

Active member
Local time
Today, 22:58
Joined
Jun 26, 2000
Messages
1,935
I've written the following code to resolve the issue, but I get error 3420 i.e. 'Object invalid or no longer set' on the line indicated.

Code:
Public Sub ChangeTableFieldFormat(strTable As String, strFieldName As String)

    Dim tdf As DAO.TableDef
    Dim fld As Field
    Dim prp As Property
    
    Set tdf = CurrentDb.TableDefs(strTable)
    Set fld = tdf.Fields(strFieldName) 'ERRORS HERE
    Set prp = fld.CreateProperty("Format", dbText, "Fixed")
    
    fld.Properties.Append prp
    
    Set tdf = Nothing
    Set fld = Nothing
    Set prp = Nothing
    
End Sub
 

aziz rasul

Active member
Local time
Today, 22:58
Joined
Jun 26, 2000
Messages
1,935
It's OK folks, I got the solution from another source. The code should have been

Code:
Public Sub ChangeTableFieldFormat(strTable As String, strFieldName As String)

    Dim tdf As DAO.TableDef
    Dim fld As DAO.Field
    Dim prp As DAO.Property
    
    With CurrentDb
        Set tdf = .TableDefs(strTable)
        Set fld = tdf.Fields(strFieldName)
        Set prp = fld.CreateProperty("Format", dbText, "Fixed")
        
        fld.Properties.Append prp
        
        Set tdf = Nothing
        Set fld = Nothing
        Set prp = Nothing
    End With
    
End Sub
 

Users who are viewing this thread

Top Bottom