473,395 Members | 1,790 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,395 software developers and data experts.

Repeating values for a field in several records

I am using Access 2007, and I have a database in which one field is likely to have the same value for several records (eg the Age field in a table of students). How can I set this field on a form so that when a new record is created, the Age field defaults to the value used in that field on the previous record (so that I don't have to keep entering the same data)?

Thanks in advance.

Robert
Sep 5 '07 #1
7 8356
MikeTheBike
639 Expert 512MB
I am using Access 2007, and I have a database in which one field is likely to have the same value for several records (eg the Age field in a table of students). How can I set this field on a form so that when a new record is created, the Age field defaults to the value used in that field on the previous record (so that I don't have to keep entering the same data)?

Thanks in advance.

Robert
Hi

In my humble opinion, I think you should be storing the date of birth not the age (which changes)!!??

As usual there are many ways to do this I'm sure, but of the top of my head, this is one way

Declare a module level variable, say intAge

in the form before update event set this to intAge = age_control

in the form on current event set the age_control = intAge IF it is a new record
ie If Me.NewRecord Then age_control = intAge

This may need tweeking, depending on how the form operates.


MTB
Sep 5 '07 #2
FishVal
2,653 Expert 2GB
I am using Access 2007, and I have a database in which one field is likely to have the same value for several records (eg the Age field in a table of students). How can I set this field on a form so that when a new record is created, the Age field defaults to the value used in that field on the previous record (so that I don't have to keep entering the same data)?

Thanks in advance.

Robert
Hi, Robert.

I suggest you to set DefaultValue property to current control value on AfterUpdate event.

Example for Date type field
Expand|Select|Wrap|Line Numbers
  1. Private Sub dteDate_AfterUpdate()
  2.     With Me.dteDate
  3.         .DefaultValue = "#" & .Value & "#"
  4.     End With
  5. End Sub
  6.  

Example for Numeric type field
Expand|Select|Wrap|Line Numbers
  1. Private Sub lngNum_AfterUpdate()
  2.     With Me.lngNum
  3.         .DefaultValue = .Value
  4.     End With
  5. End Sub
  6.  

Example for Text type field
Expand|Select|Wrap|Line Numbers
  1. Private Sub txtText_AfterUpdate()
  2.     With Me.txtText
  3.         .DefaultValue = "'" & .Value & "'"
  4.     End With
  5. End Sub
  6.  
Sep 5 '07 #3
Hi, Robert.

I suggest you to set DefaultValue property to current control value on AfterUpdate event.

Example for Date type field
Expand|Select|Wrap|Line Numbers
  1. Private Sub dteDate_AfterUpdate()
  2.     With Me.dteDate
  3.         .DefaultValue = "#" & .Value & "#"
  4.     End With
  5. End Sub
  6.  

Example for Numeric type field
Expand|Select|Wrap|Line Numbers
  1. Private Sub lngNum_AfterUpdate()
  2.     With Me.lngNum
  3.         .DefaultValue = .Value
  4.     End With
  5. End Sub
  6.  

Example for Text type field
Expand|Select|Wrap|Line Numbers
  1. Private Sub txtText_AfterUpdate()
  2.     With Me.txtText
  3.         .DefaultValue = "'" & .Value & "'"
  4.     End With
  5. End Sub
  6.  

Thanks, but I couldn't get it to work.

I tried with a numeric field and also a text field, without success.

My numeric field is called Age and I entered the code as you suggested. It looks like this:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Age_AfterUpdate()
  2.     With Me.Age
  3.         .DefaultValue = .Value
  4.     End With
  5. End Sub
  6.  
I presume the "Me" is a generic reference to the current form, but I tried the full form name as well, also without success.

Do you have any other suggestions for what I might be doing wrong?

Thanks

Robert
Sep 6 '07 #4
FishVal
2,653 Expert 2GB
Thanks, but I couldn't get it to work.

I tried with a numeric field and also a text field, without success.

My numeric field is called Age and I entered the code as you suggested. It looks like this:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Age_AfterUpdate()
  2.     With Me.Age
  3.         .DefaultValue = .Value
  4.     End With
  5. End Sub
  6.  
I presume the "Me" is a generic reference to the current form, but I tried the full form name as well, also without success.

Do you have any other suggestions for what I might be doing wrong?

Thanks

Robert
Hi, Robert.
The code was tested multiple times before. It just must work. ;)
1. Did you set Age.AfterUpdate property to "[Event procedure]"?
2. Toggle breakpoint on the line
Expand|Select|Wrap|Line Numbers
  1. Private Sub Age_AfterUpdate()
  2.  
and debug the sub.
I presume the "Me" is a generic reference to the current form
Yes. It is reference to the form - owner the form module.
Sep 6 '07 #5
Hi, Robert.
The code was tested multiple times before. It just must work. ;)
1. Did you set Age.AfterUpdate property to "[Event procedure]"?
2. Toggle breakpoint on the line
Expand|Select|Wrap|Line Numbers
  1. Private Sub Age_AfterUpdate()
  2.  
and debug the sub.

Yes. It is reference to the form - owner the form module.

Thanks, and OOPS!!!

My version of Access (perhaps all of them) has a security warning saying that "Certain content in the database has been disabled." When I clicked the Options to "Enable this content" everything worked fine.

Sorry that my ignorance caused you to spend time unnecessarily on this.

Thanks (and sorry) again

Robert
Sep 6 '07 #6
Hi

In my humble opinion, I think you should be storing the date of birth not the age (which changes)!!??

MTB
I agree, but I was just using this as an example - I actually have several fields which I want to repeat.

The problem has now been solved.

Thanks

Robert
Sep 6 '07 #7
FishVal
2,653 Expert 2GB
Thanks, and OOPS!!!

My version of Access (perhaps all of them) has a security warning saying that "Certain content in the database has been disabled." When I clicked the Options to "Enable this content" everything worked fine.

Sorry that my ignorance caused you to spend time unnecessarily on this.

Thanks (and sorry) again

Robert
Not a problem.
You are welcome.

Regards,
Fish
Sep 6 '07 #8

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

Similar topics

0
by: Duncan Smith | last post by:
Hello, I'm not very experienced in SQL and I need some advice. I have a comma separarated values file containing around 20 million records and about 20 fields. There are many missing values...
3
by: JOEP | last post by:
What do I need to do to allow an append query to post null values to records in a field of the destination table? Basically I want to allow records with null values to post to the table. The append...
3
by: Chuck | last post by:
Hi, I have a somewhat unique problem (at least unique to me, and I've been doing this for longer than I care to admit). I have a client that needs to print cards onto perforated card stock (so...
2
by: Alpha | last post by:
I have a C# program that user would select several search criteria and then outputs to the Crystal Report. A message is output to user if no matching record is found. In my code I also clear,...
1
by: cweibel | last post by:
This should be an easy problem for those with far more knowledge than myself with databinding. I have a VB.NET 2005 windows form with several checkboxes, textboxes and datepickers which are...
11
by: Alan Mailer | last post by:
A project I'm working on is going to use VB6 as a front end. The back end is going to be pre-existing MS Access 2002 database tables which already have records in them *but do not have any...
2
by: Pete | last post by:
I need to create a single query (Not a SQL query) against a single table that counts the number of records in the table, where the single field "tmp" contains specific string values If the field...
4
by: greg | last post by:
Hi, I don't think my message posted correctly so here it is. Is there any way to access the individual values of a form text box? I want to iterate through all of the rows and access the...
1
by: Swede.Swede | last post by:
Hello! Customer wants a gridview displaying individuals who have taken part in courses. The gridview should be sorted by the name of the participant. If a person has taken part in several...
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: 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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.