Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access
|
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 21st, 2005, 10:43 AM
Registered User
 
Join Date: Jun 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Automatically select value from a calculated field

Hello to everyone...

I have a calculated(unbound) text field named(Age) on my main form. The Age is calculated based on patient's DOB(Date of Birth) Field using datediff function, and in the subform, I have a field named (AgeNo).

There is a criteria for AgeNo Field depending on (Age) field for each patient.

Criteria:

If Age is 18-40 = AgeNo should be 0
If Age is 41-60 = AgeNo should be 1
If Age is 61-70 = AgeNo should be 2
If Age is >71 = AgeNo should be 3

MRN (Med. Rec. No) field & Age are in Main form and AgeNo field is in a subform.
I want the AgeNo field to automatically select ( 0, 1, 2 or 3 ) based on the calculated unbound text field(Age) but for some reason, the Dlookup function can't capture the Age(unboound field). Is there another way of doing this? Thanks...

here's the code:
Private Sub Form_Current()
Dim bytAge As Byte

bytAge = Nz(DLookup("[Age]", "tblPatient_Demographics", "[MRN] = '" & Me.MRN & "'"), 0)

Select Case bytAge
Case 18 To 40
Me.AgeNo = 0
Case 41 To 60
Me.AgeNo = 1
Case 61 To 70
Me.AgeNo = 2
Case 71 To 150
Me.AgeNo = 3
End Select
End Sub


Many thanks...:)






Similar Threads
Thread Thread Starter Forum Replies Last Post
Grouping with calculated field in report jack123 Access 3 August 9th, 2007 06:46 AM
Form's calculated field not working properly PaulJH Access 11 March 5th, 2007 09:52 AM
How to create a Calculated Field fdtoo SQL Server 2000 0 April 11th, 2006 08:34 PM
Auto Calculated Field in Access anubhav.kumar Access 1 March 15th, 2005 08:37 AM
Validate calculated field in sub form MG76 Access 4 March 18th, 2004 04:26 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.