Solved

Assign default value when creating table in ACCESS 2003

Posted on 2009-07-09
10
343 Views
Last Modified: 2013-11-25
Is there a way to create a default value for a column when creating a table in ACCESS 2003?  the only documentation I can find indicates to use the ALTER TABLE statement, but is there a way to simply assign it when first creating the table?  I want the Match column to default to NO.  Also, is there a way to tell the process this should also be a checkbox, which by default is no?
strCreateTable = "CREATE TABLE tblTEMPWeeklyApps (Campaign_ID Integer, SSN Text(12), " & _
    "Booked Integer, Approved Integer, AppDate Date, Age Integer, " & _
    "Reference Text(20), AddrType Integer, DNIS Text(10), AppEID Text(20), " & _
    "Match Bit DEFAULT 'No')"

Open in new window

0
Comment
Question by:ssmith94015
  • 5
  • 3
10 Comments
 
LVL 75

Assisted Solution

by:DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform) earned 100 total points
ID: 24816119
0
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 400 total points
ID: 24816295
after you create the table you need more code to set the values properties

dim db as dao.database, fd as dao.field, pt as dao.property

strCreateTable = "CREATE TABLE tblTEMPWeeklyApps (Campaign_ID Integer, SSN Text(12), " & _
    "Booked Integer, Approved Integer, AppDate Date, Age Integer, " & _
    "Reference Text(20), AddrType Integer, DNIS Text(10), AppEID Text(20), " & _
    "Match Bit)"

db.execute strCreateTable

Set fd = db.TableDefs("tblTEMPWeeklyApps").Fields("Match")
    fd.DefaultValue = 0
Set pt = fd.CreateProperty("DisplayControl", dbInteger, 106)
    db.TableDefs("tblTEMPWeeklyApps").Fields("Match").Properties.Append pt
0
 

Author Comment

by:ssmith94015
ID: 24816942
I was afraid I was stuck with the ALTER TABLE so that is the route and simplest.
0
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 

Author Comment

by:ssmith94015
ID: 24816962
Capricorn, yours was a way to do it, but more complicated than what I needed.  But thank you.
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 24816972
what about
< Also, is there a way to tell the process this should also be a checkbox>
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 24817000
i don't think it is fair that you will select a suggestion that only fulfills part of your requirement when there is  a complete solution offered.
0
 

Author Comment

by:ssmith94015
ID: 24818316
OH MY GOSH, I completely missed that.  You are so correct, I will contact Adminiistration here and get some points moved.  
0
 

Author Comment

by:ssmith94015
ID: 24818354
Cap, I have sent a request for attention and am requesting 400 points to be moved to you.  I am so very sorry, it has been a long continuous day-night-day and I missed what you were telling me.  Your response was the complete answer and does work but in the time alloted to get this out the door I did use the ALTER statement.
0
 

Author Closing Comment

by:ssmith94015
ID: 31601735
Thank you both and Cap, I again apologize as your works and is complete.  To be fair,  I did give points to DatabaseMX as that was the route I took at the time.
0

Featured Post

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

Suggested Solutions

QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

860 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