IIF Statement using DateAdd?

B

bdmagnum

Hello to all,
I had posted a few questions earlier in the week and found the answers
As I said in my earlier post, I am working on a database dealing wit
306 Security Badges.

I have a TextBox "Check-In Date" that will input the current date whe
double clicked.

I have a pulldown ListBox "Status" with the choice of "STAFF" o
"STUDENT".

I also a blank TextBox "Expiration" that should present a future dat
based on "STAFF" (3 years from current date) and "STUDENT" (1 year fro
current date).

I have searched many hours for a possible solution and have come acros
DateAdd. I believe my situation also needs an IIF statement, but no
sure.

My question is as follows:

What code/formula should I use to achieve my goal and where do I pu
the code/formula(Control Source of "Expiration", After Update in one o
the three fields, in a query, etc.).

Thanks for responding,
Bil
 
S

Steve Schapel

Bill,

You are right that the DateAdd function is applicable here. I would be
inclined to use code on the AfterUpdate event of your Status combobox to
adjust the date in the Expiration textbox. It might look something like
this...

Private Sub Status_AfterUpdate()
Dim Interval As Integer
If IsNull(Me.Status) Then
Me.Expiration = Null
Else
Select Case Me.Status
Case "STAFF"
Interval = 3
Case "STUDENT"
Interval = 1
End Select
Me.Expiration = DateAdd("yyyy", Interval, Date)
End If

End Sub
 

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

Top