Solved

Default values for Access fields

Posted on 1998-08-27
4
156 Views
Last Modified: 2010-08-05
Is there any way to set the default value of a field when you use the ALTER TABLE command to create new fields on an Access table? Currently it defaults to null, but I need it to be zero.
0
Comment
Question by:BergJC
  • 2
4 Comments
 
LVL 1

Expert Comment

by:DennisH
ID: 1431350
Would it be possible to use DAO for this?  It's a lot easier that way.  Then after you create the fields in the table, you can select the Field object from the Fields collection of the table and set it's Default property.  
0
 
LVL 2

Author Comment

by:BergJC
ID: 1431351
I don't know if DAO would work...could you show me how this could be done?
0
 
LVL 9

Accepted Solution

by:
Dalin earned 100 total points
ID: 1431352
BergJC,
Try this:

Dim MyDB As Database
Dim tdfMyTable As TableDef

Set MyDB = OpenDatabase("YourDBNAmeWithPath")
Set tdfMyTable = MyDB.TableDefs!YourTableNAme

tdfMyTable.Fields!PostalCode.DefaultValue = "0" ' Or 0 without quote, depend on how you define it

MyDB.Close
0
 
LVL 9

Expert Comment

by:Dalin
ID: 1431353
You should replace "PostalCode" with your fieldName
    tdfMyTable.Fields!YourFieldNAmeHere.DefaultValue = 0 ' assume it is a number field
Regards
Dalin
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

786 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