Thanks once again DatabaseMX,
How do I set this up in code?
Main Topics
Browse All TopicsI 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.
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.
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.
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.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
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.
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
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
I tried to put the following code in the Macro section:
Private Sub Form_ActualFormName(Cancel
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?
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
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.
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.
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
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/Ex
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
DatabaseMX,
Thanks again for your time. I have uploaded the file and was given this link:
http://www.ee-stuff.com/Ex
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.
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
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.
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.
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
Business Accounts
Answer for Membership
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