472,807 Members | 3,826 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

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 10306
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*********@btconnect.com> wrote in message
news:bj**********@titan.btinternet.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.OpenRecordset("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*******************@news-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*********@btconnect.com> wrote in message
news:bj**********@titan.btinternet.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
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...
7
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 ...
8
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...
7
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...
6
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...
1
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...
13
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...
9
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...
0
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...
1
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...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?

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.