Question

Access Default Value = Another Columns Value

Asked by: jjrr007

I just wanted to ask how I can set a default value in MS Access that is equat to another column in the same row.  Also, I want to set another column's default value to be 2 higher than another column in the same row.  Could you please let me know how to do that?  Thanks.

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2007-08-05 at 17:50:52ID22743272
Tags

value

,

access

,

default

,

another

,

column

Topics

Access Architecture/Design

,

Microsoft Access Database

,

Access Forms

Participating Experts
2
Points
500
Comments
25

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. difficult equation
    i have been given a so called simple equation to solve but if this is a simple equation after only 5 months of programming then god knows what the next 4 years is going to bring i am to design a program that will ask the user to enter any number of columns and any number of...
  2. "Find" equation..
    Hi, I'm a rookie to excel, and i'm having trouble w/ equations, so please help me out here 1) in "cell AA1", find the value D3 in the range M3:M51.. when there's match (eg. D3=M42), then display value of N42 (1 column to the right) IN cell AA1 2) in "cell AB1...
  3. Sorting Rows on the value of column..
    I want to sort worksheet rows on the base of particular column or columns value then I want to show only 20 top rows on worksheet for example (If we see the stock list the top 20 companies will show on the worksheet on the base of one week data). How can I do this? Thank You
  4. specify last row for equation
    as I asked in the earlier question...I need to specify the last row from within an equation...very concerned about execution and calculation speed...so I want to minimize the steps involved. Is there a way to specify the last row of a range that you wish to use in a calculat...
  5. Equation for reference of current cell?
    Is there an equation that would give you the cell reference for the current cell that it is being calculated in?
  6. Partitioned row number column in MS Access
    Via C#.NET (OleDB), I would like to add a column to an Access table that will give every row a rank, or row number, partitioned by a value in another column. To do this using SQL Server I would add the following code to my Select statement: Row_Number() OVER(PARTITION BY a...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: DatabaseMXPosted on 2007-08-05 at 17:53:50ID: 19635874

You cannot do that in table design.

You would have to do that in code.

mx

 

by: jjrr007Posted on 2007-08-05 at 17:56:43ID: 19635882

Thanks once again DatabaseMX,

How do I set this up in code?

 

by: DatabaseMXPosted on 2007-08-05 at 18:01:35ID: 19635888

Where do you have the 1st default value set?  Table or Form level ?

This is what I would do:

Private Sub Form_BeforeInsert(Cancel As Integer)
    Me.SomeTextBox1 = "someDefaultValue"
    Me.SomeTextBox2 = "someOtherDefaultValue"
End Sub

As soon as the user types in any bound field on the Form ... the default values will be set.

mx

 

by: jjrr007Posted on 2007-08-05 at 18:04:20ID: 19635896

I would like to set this up at the table level.  That way If I need to import data using Excel, then I  will not need to import as many columns.  Should I use the code above for that?

 

by: DatabaseMXPosted on 2007-08-05 at 18:10:13ID: 19635916

Well, if you are just importing into a table, then that code will not help.  At the table level, you cannot reference a default value from another column, sorry.

mx

 

by: GRayLPosted on 2007-08-05 at 18:17:24ID: 19635957

It begs the question: "Why store a value that is 2 higher that another column when that value is 'instantly' available via a query?  You should never store derivable values unless you have a very good reason, like security for example."

 

by: jjrr007Posted on 2007-08-05 at 18:24:01ID: 19635984

I will be importing data from Excel at times as well as using a form to enter data.  I could use the code you have above for the form. I am just not sure what to put for "someDefaultValue"- I want this to be set to another field.  Thanks,

 

by: jjrr007Posted on 2007-08-05 at 18:27:20ID: 19635999

That is true, I am using an existing application that uses the other column.  So I have no control on how they do this.  

For the first field I need to set it's a date/time column. So should I change the code to:

Private Sub Form_BeforeInsert(Cancel As DateTime)
    Me.SomeTextBox1 = Me.SomeTexBoxtBox2
End Sub

 

by: DatabaseMXPosted on 2007-08-05 at 18:34:05ID: 19636008

Well .. you said two higher than another value ... so for example:


Private Sub Form_BeforeInsert(Cancel As Integer)
    Me.SomeTextBox2 = Me.SomeTextBox1.DefaultValue + 2    
End Sub

This assumes you have the default value for textbox1 set in the table.

Something like that ?

 

by: jjrr007Posted on 2007-08-05 at 18:35:26ID: 19636010

I tried to put the following code in the Macro section:

Private Sub Form_ActualFormName(Cancel As DateTime)
    Me.StartDate = Me.EndDate
End Sub

When I go to the form, I don't have the EndDate field automatically equalt the StartDate field.  Is there something different I should do.  Do I need to execute this code or put this somewhere else?

 

by: jjrr007Posted on 2007-08-05 at 18:42:05ID: 19636021

Hi DatabaseMX,

Thanks again for your assistance. One of the fields on the form should be set automatically equal one of the other fields.  Also, I wanted another field to be 2 greater than another field. My main focus is getting the field that equals another field set properly.  

I wanted to kindly ask if I have the correct syntax below?  

Private Sub Form_ActualFormName(Cancel As DateTime)
    Me.StartDate = Me.EndDate
End Sub

When I go to the form, I don't have the EndDate field automatically equal the StartDate field.  I enter this as a Macro or should I enter this somewhere else?  The EndDate field should automatically update.

 

by: jjrr007Posted on 2007-08-05 at 18:46:24ID: 19636029

I'm sorry I mean that I entered this as a Module. Should I go somewhere else to put the code?  Based on your most recent post I have updated the Module to:

Private Sub ActualFormName(Cancel As DateTime)
    Me.StartDate = Me.EndDate.DefaultValue
End Sub

I'm not gettng the EndDate field equal to the StartDate field.  I'm not sure what I'm doing wrong.

 

by: DatabaseMXPosted on 2007-08-05 at 18:48:58ID: 19636038

Well... this should work:

Private Sub Form_BeforeInsert(Cancel As DateTime)
    Me.StartDate = Me.EndDate
End Sub

"Private Sub Form_ActualFormName(Cancel As DateTime)"

That is not really an Event on the form.  All Form events are of the syntax
Private Sub Form_<event name> (<SomeArgument> sometimes)

mx

 

by: DatabaseMXPosted on 2007-08-05 at 18:52:59ID: 19636044

No ...  not in an external module.  You put it in the BeforeInsert event on your form.

On the Form's property sheet ... Event tab ... you will see Before Insert.  Click on the three dots on the right. This will take you to code with looks like this:

Private Sub Form_BeforeInsert(Cancel As Integer)

End Sub

You add you line(s) of code - such that the end result looks like:

Private Sub Form_BeforeInsert(Cancel As Integer)
    Me.StartDate = Me.EndDate
End Sub

mx

 

by: jjrr007Posted on 2007-08-06 at 16:41:14ID: 19642416

DatabaseMX,

I followed the steps you mentioned in your most recent post.  For some reason, the end date column is not automaticallys et. What do you think I should do?  

Also, for the second value I am trying to set.  How do I say that the default value of EndTime is 4 hours after StartTime?

 

by: DatabaseMXPosted on 2007-08-06 at 16:46:06ID: 19642439


You can use Me.EndTime = DateAdd("h",4,[StartTime])


"What do you think I should do?  "

Can you upload to http://www.ee-stuff.com/Expert/Upload/upload.php ... removing any sensitive data of course?  

Then, provide me the link EE-Stuff gives you to the file location ... back here in this thread.

Note: There is a  4MB upload limit.

mx

 

by: jjrr007Posted on 2007-08-06 at 17:19:29ID: 19642534

DatabaseMX,

Thanks again for your time. I have uploaded the file and was given this link:
http://www.ee-stuff.com/Expert/Upload/viewFilesQuestion.php?qid=22743272

I took out the priopetary information.  Also, when I tried to add
Me.EndTime = DateAdd("h",4,[StartTime])
to the existing code, I am getting some type of error.  I think I'm doing something wrong.  

 

 

by: jjrr007Posted on 2007-08-06 at 17:45:23ID: 19642601

DatabaseMX,

I have replaced Me.EndTime = DateAdd("h",4,[StartTime])
With
Me.EndTime1 = DateAdd("h",4,[StartTime1])

I had the column named wrong.  Thanks again!

 

by: jjrr007Posted on 2007-08-06 at 17:46:10ID: 19642603

I haven't gotten it to work yet.  

 

by: DatabaseMXPosted on 2007-08-06 at 17:46:57ID: 19642604

ok ... let's review what you need here:

1) Are these the only fields on the form?
My guess there are more fields.  We need to be able to trigger the Before Insert ... by starting to type in some field ... so that we can set the default values >>>

2) When you go to a new record (where default values apply) ... what exactly do you want to happen in each of the four fields on the form you sent me.

I'm leaving work ... will back online in a couple of hours ...

until then ...

mx

 

by: jjrr007Posted on 2007-08-06 at 18:24:27ID: 19642725

DatabaseMX,

Yes, there are some other fields on the form.  There is another column that comes before the "StartDate" and some columns after "EndTime1".  

What i'm utimately trying to do is have to type in less values in this form.  Either if I type in the form or paste from Excel (ideally the default values can work both ways, either way of inputting is fine).  I would like the "StartTime1" colum to pull the time from "StartDate"  (I was going to make a change to the code, but I found it easier to explain it the way I did).  That way there will be less data to enter.  If there is a value put in for StartTime1 then it will use that.  So I thought an default value was ideal.

For the second part, I would like the field "EndTime1" to be 4 hours after the field "StartTime1" as a default value.

 

by: DatabaseMXPosted on 2007-08-06 at 21:37:00ID: 19643337

"I would like the "StartTime1" colum to pull the time from "StartDate" "

Sorry ... but I am confused.  How do you want to pull a Time from a Date ?

"So I thought an default value was ideal."

What do you want the default values to be ... and where?

mx

 

by: jjrr007Posted on 2007-08-07 at 21:23:56ID: 19651460

DatabaseMX,

I appreciate your time and assitance.  Based on this question and other questions you have helped me with, I think you are very good at these things.  Thanks again.

The column "StartDate" contains a time as well.  I would like the default value of "StartTime1" to be obtained by getting the time from the "StartDate" column.  Also, I would please like the default value of "EndTime1"- to be 4 hours after the time entered for "StartTime1".  

In terms of where the default values will be set; i think you mentioned that this could be done on the form and not on the table.  I would prefer on the table, but the form will work.

 

by: jjrr007Posted on 2007-08-07 at 21:25:26ID: 19651466

BTW, I can change the format of the StartDate Column so that it more easily shows the time and the date if need be.

 

by: DatabaseMXPosted on 2007-08-07 at 22:51:24ID: 19651793

Ok ... Do this:

1) On the property sheet for StartDate - set the Default Value to
Now()

2) Put THIS code in the BeforeInsert event ... I'm showing the entire event here:

Private Sub Form_BeforeInsert(Cancel As Integer)
    Me.StartTime1 = TimeValue(Me.StartDate)              '** THIS LINE
    Me.EndTime1 = DateAdd("h", 4, Me.StartTime1)     '** And THIS LINE
End Sub

So ... for example ... as soon as say ... you type something(the first character) in Project ID ..
StartTime 1 will populate with the Time Value of Now()
and
EndTime 1 will populate with 4 hours later than that.

mx

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...