473,396 Members | 1,765 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How to Increment Default Value for Each New Record

124 100+
I have a form with two textboxes: txtSortOrder and txtCourse. I want the txtSortOrder's default value to increment by 10 for each new record (this is to save data entry time). So, if I type in 10 for the first record, the default value for the second record is 20 and so on. Right now I have this code on the form's AfterUpdate event:

Expand|Select|Wrap|Line Numbers
  1. If Not IsNull(Me.txtSortOrder) Then
  2.     Me.txtSortOrder.DefaultValue = Me.txtSortOrder.DefaultValue + 10
  3. End If
  4.  
However, this doesn't entirely work the way I want it to. For the first record, when I type in 10 for txtSortOrder, and then a value for txtCourse, Access creates a new blank record but with a txtSortOrder default value of 10, not 20. However, when I click on txtCourse for the new record, the default value then changes to 20. It appears that my code triggers once I select the new record but I want it to happen as soon as Access creates the new blank record for me.
I've tried adding this code to the form's AfterUpdate, AfterInsert, and BeforeInsert events. I also tried adding it to txtSortOrder's BeforeUpdate and AfterUpdate events. However, none give me the desired result. The default value for txtSortOrder only increments when I click on the new record. Is there a way to get what I want? If so, how?
Sep 28 '10 #1
1 4579
nico5038
3,080 Expert 2GB
Dear bullfrog83,

I don't see a reason to store a value like this, as it's deductable from your table. Looks to me that using the DCOUNT() function in your txtSortOrder field will get the value displayed like:
Expand|Select|Wrap|Line Numbers
  1. =DCOUNT("id","tblID","where for grouping when needed") * 10
  2.  
When you want to offer the user an additional way to change the sortorder you might be interested in my sample database.

See:
http://bytes.com/attachments/attachm...tright2000.zip

Nic;o)
Sep 28 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Kajol | last post by:
Hi All, I am using server version: 4.1.11-nt on windows 2000. I want to create a table with ID as auto increment and initialise it with a starting value of 1000. I am trying to do following...
11
by: David Messner | last post by:
Ok I know this is simple but the statement eludes me... I have a date field where I want the default value on the data entry form's date field to be the last date entered. I figure I can do this...
8
by: ISmith | last post by:
Hi, I am trying to increment a field on a form after a record has been stored. It is a standard fumeric field which may contain some blocks of consecutive values in the table but is not meant to...
21
by: planetthoughtful | last post by:
Hi All, As always, my posts come with a 'Warning: Newbie lies ahead!' disclaimer... I'm wondering if it's possible, using raw_input(), to provide a 'default' value with the prompt? I would...
6
by: carmela_wong | last post by:
Hello all, I am trying to set the default value of a combo box to "USA" which does not work although I have entered this in the Default Value property of the control. The combo box shows the...
4
by: Torilyn73 | last post by:
I have a combo box set up off a query. I want the default value to be the column heading so I don't have to put a label over it. So far I haven't been able to figure this out. Can anyone tell me if...
2
by: sparks | last post by:
I am trying to set the default value on a forms field to the filter that I am passing to the form. The filter works fine but the field comes up blank. So I put in a default value and it works...
9
isben22
by: isben22 | last post by:
I had a resource for this in the past but lost it somewhere... I have a need to enter daily information. Every day has to be accounted for, 24/7. I would like to make the default value of the...
10
by: Brad Baker | last post by:
I have an asp.net/csharp application that requires a particular variable to work properly. This variable is usually passed via a query string in the URL when the application is first run but under...
43
by: kenneth | last post by:
Dear all, I have encountered this weird problem. I have a class definition with an __init__ argument 'd' which defaults to {}. This argument is put in the 'self.d' attribute at initialization...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.