Solved Spell Check On Null Values Issue

.SelStart line shows the following on hover.... <Object variable or with block variable not set>

so that is a zls (not a null) as I suspected - now step through the code to the selstart line - what do you see as a value now?
 
the spell checker doesn't error BUT moves to a new field in another record
is that when there is a value? or a zls?

<Object variable or with block variable not set>
on what line?

have you tried the 'cure'?
 
@CJ_London

Tried out this recommendation and it appears to work.....

Code:
Private Sub Purpose_Agenda_AfterUpdate()
'http://eileenslounge.com/viewtopic.php?f=29&t=10183
'Skips warning message if no spelling error
    If Nz(Me.Purpose_Agenda, "") <> "" Then
        With Me.Purpose_Agenda
            .SetFocus
            .SelStart = 0
            .SelLength = Len(Me.Purpose_Agenda)
        End With
        DoCmd.SetWarnings False
        RunCommand acCmdSpelling
        DoCmd.SetWarnings True
    End If
End Sub

Just a thought - to set the selLength property, the control must have the focus - your code is in the afterupdate event which occurs before the lostfocus event so it already has the focus. Suggest comment out your setFocus line to see if that makes a difference - My thinking is that the isnull line is allowing through a zls and the setfocus 'resets' it to null

cure might be

If nz(Me.Purpose_Agenda,"")<>"" then With Me.Purpose_Agenda
 
Visual when I remove the text value and leave the cell.....
Hi. My concern was why would the code go through when there's nothing there. So, could you please try the following code for me then? Thanks.

Code:
If Me.Purpose_Agenda > "" Then
    With Me.Purpose_Agenda
    .... 'all your stuff here
    End With
End If

Edit: Oops, looks like I was too slow...
 
@theDBguy I tried your recommended code and that approach works as well.

If it mattered in the discussion, field is on the form footer, of a continuous form. I had previously tried putting the code in the BeforeUpdate but it would error out, telling me I couldn't .SetFocus. This lead me to the AfterUpdate location.

Hi. My concern was why would the code go through when there's nothing there. So, could you please try the following code for me then? Thanks.

Code:
If Me.Purpose_Agenda > "" Then
    With Me.Purpose_Agenda
    .... 'all your stuff here
    End With
End If

Edit: Oops, looks like I was too slow...
 
So why does your cure work?
the nz function gives you the opportunity to substitute null with another value (in this case a zls) so it will work whether Purpose_Agenda is a null or a zls.

My guess is you have set the properties for your underlying field to allow zero length =Yes. The usual setting is No which means a field 'converts' a zls to a null. By setting it to yes, a blank field could be a null or a zls so you have to test for both scenarios.
 

Users who are viewing this thread

Back
Top Bottom