disable field

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Dears,

how to disable field with conditons if false

e.g. I have a age field which populates age of a person with weeks. i.e. one
filed the user enters date and on these dates the age populates with weeks
e.g. 1 year 50 weeks

my question

1. if the age is 8 years or above the the date field should disable
2. if the age is 8 weeks or less the text field or date field should disable

hope its possible
plz help

thanks
 
Code and expressions will work regardless of whether or not the control on
the form is disabled. Disabling only allows you to deny physical data entry.
What you can do is use code instead of an expression to populate the field,
something like (aircode):

Sub txtBirthDate_AfterUpdate
If DateDiff("WW", Me.txtBirthDate, Date) <=8 Then
Me.txtAge = Null
Else If DateDiff("yyyy", Me.txtBirthDate, Date) <=8 Then
Me.txtAge = Null
Else
'your date expression here
End Sub
--
Arvin Meyer, MCP, MVP
Microsoft Access
Free Access downloads:
http://www.datastrat.com
http://www.mvps.org/access
 
Thx Arvin, I get a error message "Compile error, else without if"
for below code
Private Sub txtBirthDate_AfterUpdate()

If DateDiff("WW", Me.txtBirthDate, Date) <= 8 Then
Me.txtAge = Null
Else: If DateDiff("yyyy", Me.txtBirthDate, Date) <= 8 Then Me.txtAge = Null

Else:
txtAge = DateDiff("yyyy", [DOBPET], Now()) + _
Int(Format(Now(), "mmdd") < Format([DOBPET], "mmdd"))
End Sub
 
Douglas, u r a Star

Thanks a bunch ur help is appreciated

all works fine, except when I enter date as 01/01/1997, it shows 8 years 35
weeks

ideally it should show "Invalid date" i.e. even if it is 8 years 1 week ,
it should show "Invalid date"

any suggestion on this

Cheers!!

Douglas J. Steele said:
To calculate the age in years and weeks, calculate the difference in weeks.
The years will be the integer portion of the total weeks divided by 52, the
weeks will be total weeks mod 52:

However, now that I'm looking closer at your original code, I'm getting
confused. In one case it used Me.txtBirthDate, in another it used [DOBPET].
I'll assume that you have a field on your form named txtBirthDate which is
bound to the DOB field in your table. With that assumption, you need
something like:

Private Sub txtBirthDate_AfterUpdate()

If IsDate(Me.txtBirthDate) Then
If DateDiff("ww", Me.txtBirthDate, Date) < 8 Then
Me.txtAge = "Invalid Age"
ElseIf DateDiff("yyyy", Me.txtBirthDate, Date) > 8 Then
Me.txtAge = "Invalid Age"
Else
Me.txtAge = DateDiff("ww", Me.txtBirthDate, Date) \ 52 & _
" years, " & _
DateDiff("ww", Me.txtBirthDate, Date) Mod 52 & _
" weeks."
End If
Else
Me.txtAge = "Invalid Date of Birth"
End If

End Sub

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Gerald said:
Cheers, Douglas for ur suggestion..

Now, this is where I stand

DOB = date of birth in date format
age = populates age in years and weeks (as entered in DOB)

if age above 8 years 0 weeks age field should display " invalid age "
if age below 8 weeks age field should display " invalid age "

can u possibly advice how best can we do this ?

Any help will be appreciated

Many thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top