Block If not executing.

D

David Ryan

Hello all. I hope this is in the right place, I haven't used the MS
newsgroups before.
Code:
Private Sub Form_Current()

If (txtPcDate.Value > date And txtAdmDate.Value > date And
txtClinDate.Value > date) Then
cboCurrent.Value = True

ElseIf (cboCurrent.Value = True) Then
cboCurrent.Value = False

End If

DoCmd.GoToControl ("txtName")

End Sub

The database contains two tables with slightly different fields
(unfortunately I am not able to collapse them into one table) so I have two
almost identical forms to use to enter data into the tables.
On the first form, the above code works perfectly, but on the second form I
would only get the DoCmd working. The object names are all correct.
When I replaced [txtPcDate.Value > date And txtAdmDate.Value > date And
txtClinDate.Value > date] with [true] it did execute. What has me stumped is
that I am using exactly the same code and test dates in both forms but the
conditional doesn't evaluate the same on the second form.
 
A

Allen Browne

Presumably txtPcDate and txtAdamDate and txtClinDate are text boxes,
cboCurrent is a combo, and Date is the system date (*not* the name of
another field or control)?

Any chance that txtPcDate or txtAdmDate or txtClinDate could be null? If any
one is null, the If will not result in true, so the Else will execute. More
info in:
Common errors with Null'
at:
http://allenbrowne.com/casu-12.html

Hopefully cboCurrent is not bound to a control. Firstly it is wrong to store
the value that is the result of a calculation. Secondly, dirtying a record
in Form_Current just because the user moves there makes no sense. Thirdly,
if you did want to break the rules and store the value, it should be done in
the AfterUpdate of the affected controls (or the BeforeUpdate event of the
form), and not just because somebody happened to visit the record.

HTH.
 
Top