Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Set default value for a field - via VBA

Posted on 2012-12-21
4
Medium Priority
?
336 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
ID: 38713950
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 - Microsoft MVP, Access and Data Platform) earned 2000 total points
ID: 38713967
Short version:


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

mx
0
 

Author Closing Comment

by:Andy Brown
ID: 38714246
MX - As always - you are a Genius - Thank you :O)
0
 
LVL 75
ID: 38714256
You are welcome ...

mx
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

885 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