?
Solved

Set standard value in access table with vb code

Posted on 2003-02-26
6
Medium Priority
?
164 Views
Last Modified: 2008-03-10
I alter a table of an existing access 2000 database with the following vb code.

     mConn.Execute "ALTER TABLE tblArt " _
     & "ADD COLUMN Amount CURRENCY;"
     mConn.Close

This works fine but I also want to set a standerd value(default) of 0.00 for the column amount is that possible?

0
Comment
Question by:Victoria_
[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
  • 3
  • 3
6 Comments
 
LVL 18

Expert Comment

by:Sethi
ID: 8031258
This is the way to do it:
mConn.Execute "ALTER TABLE tblArt " _
    & "ADD COLUMN Amount CURRENCY Default 500.00;"
    mConn.Close
0
 

Author Comment

by:Victoria_
ID: 8032476
Dear Sethi,

I am afraid it is not that easy. I get a warning that there is a fault in the expression for the table.

0
 
LVL 18

Expert Comment

by:Sethi
ID: 8032571
Sorry. Forgot to apply square brackets around the Default statement. Use the following code, I have checked it at my end, its working fine now.
mConn.Execute "ALTER TABLE tblArt " _
   & "ADD COLUMN Amount CURRENCY [Default 500.00];"
   mConn.Close
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:Victoria_
ID: 8042499
Dear Sethi,

I have copied and pasted your code but it still does not work. The column is created but it does not set a standard default value.

I work with vb 6.0 and Access 2000. Can you please check if your deafult value is set after running the code?
0
 
LVL 18

Accepted Solution

by:
Sethi earned 300 total points
ID: 8043759
You are right. Here goes the code that works:
objConnection.Execute "ALTER TABLE  tblArt ADD COLUMN Amount CURRENCY;"
    objConnection.Execute "ALTER TABLE  tblArt ALTER COLUMN Amount SET DEFAULT 500"

After you have created a column, you can alter is default value.
0
 

Author Comment

by:Victoria_
ID: 8057751
Works smoothly, thanks for the effort
0

Featured Post

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

743 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