473,785 Members | 2,851 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Auto update database?

MVA
Hi all

I have a database where in a table (tbl_Members), there are 2 date fields
(DateOfBirth and DateJoined), and also 2 fields which upon entering the data
in the form, it automatically works out the Age (in years) and number of
DaysJoined (in days).

It works fine but it does not automatically update the Age or DaysJoined
columns on opening the form. Can anyone make a suggestion as to how I could
say, open up the Switchboard frm, and all the records in the database gets
updated?

Many thanks in advance.

Will
Nov 12 '05 #1
2 10389
Do not store the Age and DaysJoined in your table.

Instead, use a query to calculate these values, and make the query as the
RecordSource for your form. This way the value can never be wrong.

The calculated field for days joined would be:
DaysJoined: DateDiff("d", [DateJoined], Date())

For a discussion on calculating Age() see:
http://allenbrowne.com/func-08.html

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html

"MVA" <wi*********@bt connect.com> wrote in message
news:bj******** **@titan.btinte rnet.com...
Hi all

I have a database where in a table (tbl_Members), there are 2 date fields
(DateOfBirth and DateJoined), and also 2 fields which upon entering the data in the form, it automatically works out the Age (in years) and number of
DaysJoined (in days).

It works fine but it does not automatically update the Age or DaysJoined
columns on opening the form. Can anyone make a suggestion as to how I could say, open up the Switchboard frm, and all the records in the database gets
updated?

Many thanks in advance.

Will

Nov 12 '05 #2
I have a similar problem with the automated updating of a calculating
Age() field. In reading the Age() Function usage found in the
suggested link, I am not sure how to enclose the Age() function or the
code into a query being used as a RecordSource. How is this done?

Alternatively, I have some code that does the age calculation
perfectly but my problem lies in the section of code that updates each
record as it loops through the recordset. Instead of updating each
record with appropriate age, my code takes the age from the FIRST
record and inserts it into ALL records.

Please help as I am not sure where i have gone wrong with this coding.

Thanks in advance,
Robert

~~~code begins here~~~

Sub Form_Load()

Dim dbs As Database
Dim rst As Recordset
Dim strCriteria As String, strDOB As String
Dim DOB As Variant, AGE As Variant
Dim Month1 As Variant, Month2 As Variant
Dim Day1 As Variant, Day2 As Variant

~~~age calculation begins here~~~

Set dbs = CurrentDb

Month1 = Format(DOB, "m")
Month2 = Format(Date, "m")

Day1 = Format(DOB, "d")
Day2 = Format(Date, "d")

If Month1 > Month2 Then
txtAGE = DateDiff("yyyy" , txtDOB, Date) - 1

ElseIf Month1 = Month2 Then

If Day1 > Day2 Then
txtAGE = DateDiff("yyyy" , txtDOB, Date) - 1
Else
txtAGE = DateDiff("yyyy" , txtDOB, Date)
End If

Else

txtAGE = DateDiff("yyyy" , txtDOB, Date)

End If

~~~recordset loop begins here~~~

' Set search criteria.
strCriteria = txtAGE
strDOB = txtDOB

AGE = txtAGE
DOB = txtDOB

' Create dynaset-type Recordset object.
Set rst = dbs.OpenRecords et("tblPrimary" , dbOpenDynaset)

' Find first occurrence.
rst.MoveFirst

With rst

' Loop until reaching End Of Field
Do While Not rst.EOF

If (strCriteria <> !AGE) Then
' Enable editing.
.Edit

' the following fields are open for
editing
!AGE = AGE
' !DOB = DOB

' Save changes.
.Update

' Check next table record
rst.MoveNext
Else
rst.MoveNext
End If

Loop

End With

rst.Close

Set dbs = Nothing

End Sub

~~~end of code~~~

"Allen Browne" <ab************ ***@bigpond.net .au> wrote in message news:<wf******* ************@ne ws-server.bigpond. net.au>...
Do not store the Age and DaysJoined in your table.

Instead, use a query to calculate these values, and make the query as the
RecordSource for your form. This way the value can never be wrong.

The calculated field for days joined would be:
DaysJoined: DateDiff("d", [DateJoined], Date())

For a discussion on calculating Age() see:
http://allenbrowne.com/func-08.html

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html

"MVA" <wi*********@bt connect.com> wrote in message
news:bj******** **@titan.btinte rnet.com...
Hi all

I have a database where in a table (tbl_Members), there are 2 date fields
(DateOfBirth and DateJoined), and also 2 fields which upon entering the

data
in the form, it automatically works out the Age (in years) and number of
DaysJoined (in days).

It works fine but it does not automatically update the Age or DaysJoined
columns on opening the form. Can anyone make a suggestion as to how I

could
say, open up the Switchboard frm, and all the records in the database gets
updated?

Many thanks in advance.

Will

Nov 12 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2286
by: David Shorthouse | last post by:
HI is it posible to auto populate an access database.? I have 1 table structured Index_ID. - Index & auto number First_Name - Char50 Surname - Char50 Initals - Char50 Postcode - Char50 Email_Address - Char50 Mailshots - tick box
7
5047
by: Harold | last post by:
Hi, I have a question in SQL Server 2K, I use SQL Profile to trace, and find Stored Procedure was auto recompiled, like this row in the trace: SP:Recompile 15 1680 76 2004-02-27 16:01:11.610 How can I stop the auto recompile. Thanks Harold
8
749
by: Bruce Stockwell | last post by:
the setup: Webservice/WinClient application/SQL server. VS.Net (visual basic) winform wizard creates a simple form with load cancel cancelall and datagrid bound to a simple Dataset with one Datatable. No coding by programer, All wizardry. User starts app, opens form, adds (4) records and clicks update.
7
6558
by: Ugrasena via DBMonster.com | last post by:
Hi team i am using DB2 7.2 on Windows2000. We have lot many SQL Procedure Calls, is there any way i can Turn off the Auto Commit on that Database, the Problem i have is many of our Application Dont Use Auto Commit = false, and if we have any Error in the SQL procedure say after Executing 10 Update and Insert Statements the DB2 is commiting all the Previous Statements, even though there was an Error, how can i prevent this from the Database...
6
5073
by: Alpha | last post by:
I retrieve a table with only 2 columns. One is a auto-generated primary key column and the 2nd is a string. When I add a new row to the dataset to be updated back to the database. What should I do with the 1st column ? (Below I have a "1" in place for now). Also, Does the datase.AcceptChanges(); updates the changes to the database? Which command do I use to update the changes in dataset back to the Access database table? Thanks, Alpha...
1
3092
by: ainsley | last post by:
Hi this is going to sound like a very basic question, but I am creating a database in Access which is based on a number of unlimited tables. In my data entry form i have a number of combo boxes relating to these tables in which the look up field has no limit to list, as I require the users to be able to add new fields. This works fine, however, I want the fields in the table that each combo box relates to, to auto update when a new record is...
13
4728
by: S.Dickson | last post by:
I had an access database that i use as an ordering system. I have a form for entering customer details. When i add a new customer on the form the customer number is an auto number that appears when i type in the details. I have just moved over to mysql server with access as the front end. I have setup the sql tables with the customer number as autonumber. When i go into the form and add a new customer it does not generate the
9
18852
by: Beowulf | last post by:
I was having this problem: http://groups.google.com/group/microsoft.public.sqlserver.server/msg/e36e423972323378?dmode=source with it taking an inordinate amount of time to enumerate the databases on my local SQL Server instance, so I went through all the local databases and unchecked "Auto Close" on the "Options" tab of the Database properties in Enterprise Manager. This cleared up the problem nicely. In EM or through SQL-DMO, the...
0
4456
chumlyumly
by: chumlyumly | last post by:
Hello scripters - OS: Mac OSX Language: PHP w/ MySQL database I've created an insert page where a user inputs his info, which then goes to four different tables in a MySQL database. The tables are all linked with the field 'member_id', which is an auto-increment field in the parent table ('members'). I've been able to input multiple records into the other three tables 'specialty_groups', 'committee_interest' and 'committee_member'...
1
3196
by: jimilives | last post by:
I forgot to turn on auto increment when I reinstalled this database and now I have a bunch of NULL values in my ID field for last few hundred inserts, how can I update this table to replace the NULLS with a new ID value where the ID is an auto increment with out losing the ID values of old records, basically i want to do this: UPDATE ID SET id = 'NEW AUTO #' where ID = 'NULL' I hope this makes sense, I am not bound to having the numbers...
0
9480
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10152
jinu1996
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10092
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9950
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8974
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5381
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4053
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3650
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.