Solved

Set default value for a field - via VBA

Posted on 2012-12-21
4
329 Views
Last Modified: 2012-12-21
Is it possible to change the deafult value of a field (within a table), via VBA?
0
Comment
Question by:Andy Brown
  • 3
4 Comments
 
LVL 75

Expert Comment

by:DatabaseMX (Joe Anderson - Access MVP)
Comment Utility
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
0
 
LVL 75

Accepted Solution

by:
DatabaseMX (Joe Anderson - Access MVP) earned 500 total points
Comment Utility
Short version:


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

mx
0
 

Author Closing Comment

by:Andy Brown
Comment Utility
MX - As always - you are a Genius - Thank you :O)
0
 
LVL 75

Expert Comment

by:DatabaseMX (Joe Anderson - Access MVP)
Comment Utility
You are welcome ...

mx
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
In Debugging – Part 1, you learned the basics of the debugging process. You learned how to avoid bugs, as well as how to utilize the Immediate window in the debugging process. This article takes things to the next level by showing you how you can us…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now