One event two IF statements

CEH

Curtis
Local time
Today, 09:50
Joined
Oct 22, 2004
Messages
1,187
This should be simple! I'm looking at something wrong. I have two If-Else statements on the "onCurrent event of a form. ONly the first one fires. Is there something rong with the syntax???

Private Sub Form_Current()

If Me.OptInterviewed.Value = -1 Then
Me.InterviewDate.Visible = True
Else
Me.InterviewDate.Visible = False

If Me.OrientationDate.Value = -1 Then
Me.OrientationDate.Visible = True
Else
Me.OrientationDate.Visible = False

End If
End If

End Sub
 
CEH,

As originally written, the second If is evaluated ONLY WITHIN
the "Else" clause of the first If.

Code:
Private Sub Form_Current()

If Me.OptInterviewed.Value = -1 Then
   Me.InterviewDate.Visible = True
Else
   Me.InterviewDate.Visible = False
End If

If Me.OrientationDate.Value = -1 Then
   Me.OrientationDate.Visible = True
Else
   Me.OrientationDate.Visible = False
End If

Wayne
 
Hi -

You could also try:

Me.InterviewDate.Visible = Me.OptInterviewed
Me.OrientationDate.Visible = Me.OrientationDate

Bob
 
Solution........but why?

Well, changing the If-Then-Else statement in every ay I could did not work. I fixed it...... but I would like someone to tell me why it works this way.
On the 2 option groups are Select statements that control the visibility when picked....... this code

Private Sub optInterviewed_AfterUpdate()
Select Case Me.OptInterviewed
Case Is = -1
Me.InterviewDate.Visible = True
Case Is = 0
Me.InterviewDate.Visible = False
End Select
End Sub

So now instead of the "If-Then" statement on the OnCurrent event of the form I changed it to the same "Select" statements. It works. But why?
In this situation do the two events have to have statements of the same type????

Thanks
Curtis
 
Wayne's correction to your code made the code correct but didn't really solve the problem because the Current event runs only when the form is scrolled to a different record. You also needed to have the code run in the AfterUpdate event of each field as it is changed so that you will see the date field appear/disappear as appropriate.
 
Pat,
The code WAS on both events, form and textbox. But the second "IF-Then" statement on the forms Current event still was not working. Only when I changed the form to the select case did it work.
The first textbox in the "IF-Then" statement always worked correctly. But no matter how I change the IF-Then the second one refused to fire. That is until I changed the forms "On Current" event to a "Select case"
 
In your original code, the second If was only executed in the false case of the first field. Wayne fixed the code so that the two If's were independent and that should have resolved the problem.
 
Curtis, you appear to have overlooked Bob’s reply.

Regards,
Chris.
 
Didn't overlook it Chris, it wouldn't work. I think I had been looking and working with this DB too long! :) I HAD tried Waynes code before I made the post! Still it didn't work. The only thing I can think of is I must have had some small syntax error I was not seeing. I can use either way, (the "If-Then" or "Select Case" on the form "Current" event) now, and both work.
I should have done a copy and paste of the original code, I'm sure someone would have seen my error quicker. But maybe others will benefit from the post.
Thank you Pat and Wayne for your help and explanations!
 
Last edited:
CEH,

Just a thought here. Did you set a breakpoint (or put in a STOP statement)
and single-step through the code?

Wayne
 
Bob's solution

That was class! - I really liked that...

The reason for posting is that the original post did not say why it would work - and because of that I think it has been dismissed.

Option boxes (and the like) store their current state as 0 or -1 (True or False) and as such would apply perfectly to the problem posted.

Me.InterviewDate.Visible = Me.OptInterviewed (=True or False)
Me.OrientationDate.Visible = Me.OrientationDate (=True or False)

Regards
Rod
 

Users who are viewing this thread

Back
Top Bottom