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
7 8357
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
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 -
Private Sub dteDate_AfterUpdate()
-
With Me.dteDate
-
.DefaultValue = "#" & .Value & "#"
-
End With
-
End Sub
-
Example for Numeric type field -
Private Sub lngNum_AfterUpdate()
-
With Me.lngNum
-
.DefaultValue = .Value
-
End With
-
End Sub
-
Example for Text type field -
Private Sub txtText_AfterUpdate()
-
With Me.txtText
-
.DefaultValue = "'" & .Value & "'"
-
End With
-
End Sub
-
Hi, Robert.
I suggest you to set DefaultValue property to current control value on AfterUpdate event.
Example for Date type field -
Private Sub dteDate_AfterUpdate()
-
With Me.dteDate
-
.DefaultValue = "#" & .Value & "#"
-
End With
-
End Sub
-
Example for Numeric type field -
Private Sub lngNum_AfterUpdate()
-
With Me.lngNum
-
.DefaultValue = .Value
-
End With
-
End Sub
-
Example for Text type field -
Private Sub txtText_AfterUpdate()
-
With Me.txtText
-
.DefaultValue = "'" & .Value & "'"
-
End With
-
End Sub
-
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: -
Private Sub Age_AfterUpdate()
-
With Me.Age
-
.DefaultValue = .Value
-
End With
-
End Sub
-
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
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: -
Private Sub Age_AfterUpdate()
-
With Me.Age
-
.DefaultValue = .Value
-
End With
-
End Sub
-
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 - Private Sub Age_AfterUpdate()
-
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.
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 - Private Sub Age_AfterUpdate()
-
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
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
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
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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,...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
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...
| |