From: Bob07790 on
Hi
The following code runs but sometimes displaying the label when it shouldn't.
If the Me.Fault result isn't YES I sometimes get the label displaying. I
also get the same sometimes with the Me.Recoverable. If the result is
recoverable instead of not recoverable it sometimes displays the label. How
can I improve this code so that I get accurate results?

Thanks Bob


Private Sub Form_Current()

If Me.Fault = "YES" And Me.Recoverable = "NOT RECOVERABLE" And Not
IsNull(Me.NameOfOtherParty) And Me.InsuranceCompany = "BR" Or
Me.InsuranceCompany = "Br Insurance Company Ltd" Then
Me.Label476.Visible = True
Else
Me.Label476.Visible = False
End If

From: Stefan Hoffmann on
hi Bob,

On 06.03.2010 16:41, Bob07790 wrote:
> How can I improve this code so that I get accurate results?
I think there are parentheses missing:

Private Sub Form_Current()

Label476.Visible = (Me.Fault = "YES") And _
(Me.Recoverable = "NOT RECOVERABLE") And _
Not IsNull(Me.NameOfOtherParty) And _
((Me.InsuranceCompany = "BR") Or _
(Me.InsuranceCompany = "Br Insurance Company Ltd"))

End Sub

As you see, you don't need the If construct. btw, I would really
recommend that you give controls a meaningful name, if they are
referenced in code or anywhere else.


mfG
--> stefan <--
From: Bob07790 on
Stefan

Than sorted the problem, I have never seen it done like that before. I have
a few If statements like the one below, would it be better to change them to
the way you have coded it? I have also taken on board your point about
naming controls.

Thanks for your help.

Bob

"Stefan Hoffmann" wrote:

> hi Bob,
>
> On 06.03.2010 16:41, Bob07790 wrote:
> > How can I improve this code so that I get accurate results?
> I think there are parentheses missing:
>
> Private Sub Form_Current()
>
> Label476.Visible = (Me.Fault = "YES") And _
> (Me.Recoverable = "NOT RECOVERABLE") And _
> Not IsNull(Me.NameOfOtherParty) And _
> ((Me.InsuranceCompany = "BR") Or _
> (Me.InsuranceCompany = "Br Insurance Company Ltd"))
>
> End Sub
>
> As you see, you don't need the If construct. btw, I would really
> recommend that you give controls a meaningful name, if they are
> referenced in code or anywhere else.
>
>
> mfG
> --> stefan <--
> .
>
From: Bob07790 on
Stefan

Changing the following code

If Isnull (EMFund) Then
FundNote.Visible = False
Else
FundNote.Visible =True
End If

To
FundNote.Visible = (Me.EMFund = True)

This works but gives the error 94 invalid use of null when the result is False
EMFund is a Tick Box and does not have any where to allow the use of null
values.

I have changed some of my other code to this and it all works fine except
for this one. What have I done wrong?

Thanks Bob
"Bob07790" wrote:

> Stefan
>
> Than sorted the problem, I have never seen it done like that before. I have
> a few If statements like the one below, would it be better to change them to
> the way you have coded it? I have also taken on board your point about
> naming controls.
>
> Thanks for your help.
>
> Bob
>
> "Stefan Hoffmann" wrote:
>
> > hi Bob,
> >
> > On 06.03.2010 16:41, Bob07790 wrote:
> > > How can I improve this code so that I get accurate results?
> > I think there are parentheses missing:
> >
> > Private Sub Form_Current()
> >
> > Label476.Visible = (Me.Fault = "YES") And _
> > (Me.Recoverable = "NOT RECOVERABLE") And _
> > Not IsNull(Me.NameOfOtherParty) And _
> > ((Me.InsuranceCompany = "BR") Or _
> > (Me.InsuranceCompany = "Br Insurance Company Ltd"))
> >
> > End Sub
> >
> > As you see, you don't need the If construct. btw, I would really
> > recommend that you give controls a meaningful name, if they are
> > referenced in code or anywhere else.
> >
> >
> > mfG
> > --> stefan <--
> > .
> >
From: Stefan Hoffmann on
hi Bob,

On 07.03.2010 16:52, Bob07790 wrote:
> Changing the following code
>
> If Isnull (EMFund) Then
> FundNote.Visible = False
> Else
> FundNote.Visible =True
> End If
>
> To
> FundNote.Visible = (Me.EMFund = True)
>
> This works but gives the error 94 invalid use of null when the result is False
> EMFund is a Tick Box and does not have any where to allow the use of null
> values.
>
> I have changed some of my other code to this and it all works fine except
> for this one. What have I done wrong?
The simple trick is that you can use the entire If clause - which is in
fact a boolean expression - and assign it to any boolean variable or
property.

So you need:

FundNote.Visible = Not IsNull(EMFund)


mfG
--> stefan <--
 |  Next  |  Last
Pages: 1 2
Prev: subforms
Next: Step Through Code if Private Sub