Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Default values for Access fields

Posted on 1998-08-27
4
Medium Priority
?
175 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 400 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

Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

610 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