Set default value for a field - via VBA

Andy Brown
Andy Brown used Ask the Experts™
on
Is it possible to change the deafult value of a field (within a table), via VBA?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Application Developer
Top Expert 2007

Commented:
Something like this:


    Dim dbs As Database
    Dim fld As DAO.Field
    Set dbs = CurrentDb
    Set fld = dbs.TableDefs("YourTableName").Fields("YourFieldName")
    fld.DefaultValue = 0

    Set fld = Nothing
    Set dbs = Nothing

mx
Database Architect / Application Developer
Top Expert 2007
Commented:
Short version:


CurrentDb("YourTableName").Fields("YourFieldName").DefaultValue = "SomeValue" ' text example

mx
Andy BrownDeveloper

Author

Commented:
MX - As always - you are a Genius - Thank you :O)
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Application Developer
Top Expert 2007

Commented:
You are welcome ...

mx

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial