Open Form depending on criteria

  • Thread starter Thread starter Thorson
  • Start date Start date
T

Thorson

I have a form where information is entered when an animal leaves the group
due to death, euthanization, transfer or sale. On the After Update event of
the field "DispMethod" I would like a form "frmDamProductivity" to open if
the text entered is either Died, Euthanized or Sale AND if the age is <548
Days. Can I also have it calculate the age from the field "BirthDate" in
tblBirthInformation?

Can someone help me set this up?
Thanks.
 
To calculate the age in days you could add an unbound text
box to your form with a Control Source of;

=DateDiff("d", [BirthDate], Date())


To open the other form, use code like;

Private Sub DispMethod_AfterUpdate ()

If Me!DispMethod = "Died" Or _
Me!DispMethod = "Euthanized" Or _
Me!DispMethod = "Sale" Then
If DateDiff("d", [BirthDate], Date()) < 548 Then
DoCmd.OpenForm "frmYourForm"
End If
End If

End Sub
 
I entered in the following code but I must be doing something wrong... It is
a little different than yours since I decided to look up the age in days from
a query I previously created. Does it matter that txtDispMethod is on the
main form and that txtEarTag is on a subform?

Private Sub txtEarTag_AfterUpdate()
If Me!txtDispMethod = "Died" Or _
Me!txtDispMethod = "Euthanized" Or _
Me!txtDispMethod = "Sold" Then
If (DLookup("Age(Days)", "qryCurrentInventory2AllAnimals", "[EarTag]='" &
Me![EarTag] & "'") < 549) Then
DoCmd.OpenForm "frmCalfDisposal"
End If
End Sub

Thanks!
--
Thorson


Beetle said:
To calculate the age in days you could add an unbound text
box to your form with a Control Source of;

=DateDiff("d", [BirthDate], Date())


To open the other form, use code like;

Private Sub DispMethod_AfterUpdate ()

If Me!DispMethod = "Died" Or _
Me!DispMethod = "Euthanized" Or _
Me!DispMethod = "Sale" Then
If DateDiff("d", [BirthDate], Date()) < 548 Then
DoCmd.OpenForm "frmYourForm"
End If
End If

End Sub

--
_________

Sean Bailey


Thorson said:
I have a form where information is entered when an animal leaves the group
due to death, euthanization, transfer or sale. On the After Update event of
the field "DispMethod" I would like a form "frmDamProductivity" to open if
the text entered is either Died, Euthanized or Sale AND if the age is <548
Days. Can I also have it calculate the age from the field "BirthDate" in
tblBirthInformation?

Can someone help me set this up?
Thanks.
 
Back
Top