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

how do I get access to automatically update field on a form

3
This may be abit basic, I am a self taught Access user. I have a form in my database to add soldiers details and they are assigned a cohort number depending on when they enlisted. For example if they enlisted between 31/07/03 and 01/02/04 then they are in cohort 1, if they enlisted between 01/02/04 and 01/08/04 then they are cohort 2 and so on.

I want the Cohort number field to automatically upate when I enter their enlistment date (ie if they enlisted on 02/10/03 then the cohort no will automatically update to 1).

please help
Dec 4 '09 #1

✓ answered by Megalog

My suggestion is to create a table that holds your date ranges and the corresponding Cohort number, like such:

Table Name: tblDates

FieldName: ID
Type: AutoID

FieldName: StartDate
Type: Date

FieldName: EndDate
Type: Date

FieldName: Cohort
Type: Text

Then, on your form simply use this line of code in your AfterUpdate or LostFocus event for the Enlist Date field:

Expand|Select|Wrap|Line Numbers
  1. If IsDate(me.EnlistDate.value) Then
  2. Me.txtCohort.value = DLookup("[Cohort]", "tblDates", "#" & me.EnlistDate.value & "#  BETWEEN [StartDate] AND [EndDate]") & ""
  3. End If
If it doesnt find a value, it will simply leave the cohort field blank.

5 6734
Put VBA If -Then-Else Block in the BeforeUpdate event of the textbox.

Private Sub YourTextBox_BeforeUpdate(Cancel As Integer)
If DateValue("11/25/2007") = DateValue(txtReportDate) Then
cohort = 1
ElseIf DateValue("01/30/2009") < DateValue(txtReportDate) Then
cohort = 2
Else
cohort = 3
End If
End Sub

Hope that helps,
Devo
Dec 4 '09 #2
Megalog
378 Expert 256MB
My suggestion is to create a table that holds your date ranges and the corresponding Cohort number, like such:

Table Name: tblDates

FieldName: ID
Type: AutoID

FieldName: StartDate
Type: Date

FieldName: EndDate
Type: Date

FieldName: Cohort
Type: Text

Then, on your form simply use this line of code in your AfterUpdate or LostFocus event for the Enlist Date field:

Expand|Select|Wrap|Line Numbers
  1. If IsDate(me.EnlistDate.value) Then
  2. Me.txtCohort.value = DLookup("[Cohort]", "tblDates", "#" & me.EnlistDate.value & "#  BETWEEN [StartDate] AND [EndDate]") & ""
  3. End If
If it doesnt find a value, it will simply leave the cohort field blank.
Dec 4 '09 #3
Samc
3
Thanks for your help. I have created the table and put in the code as you have suggested but when i enter the date into the form i get this message

Compile error: Method data member not found

and the txtCohort bit in the code is highlighted. Could it be a problem that the the field in the newly created tbl is called Cohort and the field in the form is also called Cohort? how do I proceed?
Dec 8 '09 #4
Megalog
378 Expert 256MB
I would rename the field you have on the form to 'txtCohort', and update any other code you have that may be referencing it. Or you could change the 'me.txtCohort.value' section of my code to 'me.Cohort.value', to match what you already have in place.

Either way should work.
Dec 11 '09 #5
Samc
3
Thanks I did manage to sort that actually and it does work now so thank you. I do have another small problem tho. Its not giving me the correct value in the cohort field. For example in the table as follows (shortened version)

Start Date End Date Cohort
01/01/1900 31/07/03 Pre
01/08/03 31/01/04 1
01/02/04 31/07/04 2

If I add 02/08/03 it answers Pre, 03/10/03 also answers Pre (both should be 1), while 02/08/04 comes out at 2 (it should be 3). The dates in the table are correct so could it be a formatting issue. I really have no idea how to correct it.
Dec 14 '09 #6

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

Similar topics

3
by: BlackFireNova | last post by:
This concerns an Access 2002 (XP) database. There are two fields, "Notes" (Memo Field) and "Notes Update" on a form (among others) which I am concerned with here. Problem: I need to be able...
4
by: Terry | last post by:
Hello, I am designing a form from scratch and need to know how to get a Check Box(PASS)to automatically update when the data in a Text Box (MARK), in the same form, is >=24. Using the Event...
1
by: Kelly Olsen | last post by:
I have created an automatic update field in my Vendor_Table that automatically updates the date in that field to respond to any changes made to the record. However, I would like to display this...
1
by: Jimmy | last post by:
I have a table that is shown below in ORIGINAL TABLE. It is common for the VEHICLE # field to have repeating vehicles (ID 3,4,5 & 8,9). Usually the Vehicle will have SHIPDATE, DATE_RECEIVED, and...
6
by: John | last post by:
I have a multi-user Access database with back- and front end on the network. Problem is that the forms don't get refreshed automatically: if user A enters a record it will only become available to...
2
by: yeeehooo | last post by:
I have built a form that tracks our paperwork as it is processed. I need to include time frames from the date the paperwork is received to the date it is complete. I have four fields in the...
2
by: vijimca2004 | last post by:
Sir: Tell me the code for automatically update the particular field in table depend on particulat time using mysql 4.0 I get problems in this concept.example one field value is set to...
2
by: rlsj | last post by:
I noticed EXCEL can automatically update a list from SharePoint services. Is there a quick and easy way to update a list from an Access query? Is it "better" to create the code in ACCESS...
4
by: Kelly Warden | last post by:
I want to create a form in Access to update my table automatically with the information selected from combo boxes, lists, comments, etc. Also, I want to automate this w/ some VBA or SQL or...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: 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
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
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...
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.