Results 1 to 2 of 2
  1. #1
    5 Star Lounger
    Join Date
    Mar 2001
    Thanked 0 Times in 0 Posts

    Removing a default value (2002)

    Is it possible to remove the default zero value (0) for all numeric/ currency fields? If so, how? Thanks, Andy.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Thanked 28 Times in 28 Posts

    Re: Removing a default value (2002)

    As far as I know, Access will always set the default value for newly created number/currency fields to 0, there is no way to avoid that. You can create VBA code that clears the default value in all existing number/currency fields in a specific table, or in all tables. For example:

    Sub ClearZeroDefaultValues()
    Dim dbs As DAO.Database
    Dim tdf As DAO.TableDef
    Dim fld As DAO.Field
    Set dbs = CurrentDb
    For Each tdf In dbs.TableDefs
    If Not Left(tdf.Name, 4) = "MSys" Then
    For Each fld In tdf.Fields
    Select Case fld.Type
    Case dbByte, dbInteger, dbLong, dbSingle, dbDouble, dbCurrency
    fld.DefaultValue = ""
    End Select
    Next fld
    End If
    Next tdf
    Set fld = Nothing
    Set tdf = Nothing
    Set dbs = Nothing
    End Sub

    You must set a reference to the Microsoft DAO 3.6 Object Library in Tools | References for this code to work.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts