Need a code for IF Null

Samrasr

Registered User.
Local time
Today, 11:41
Joined
May 5, 2007
Messages
21
I have put this code under my spell check button to spell check my notes field, but if there are no notes and i click on the spell button. I get Run time error. Invalid use of Null.

What can i put so that if there is no text in the notes and i click on the spell button, it then displays a msg saying it cant check spelling as there is nothing in the notes box


With Me.FieldName
.SetFocus
.SelStart = 0
.SelLength = Len(Me.FieldName)
End With
DoCmd.RunCommand acCmdSpelling
 
Was just getting ready to send you this in response to your other posting! It's the same code, but checks to make sure that the field actually has data in it before running Spell Check! Also temporarily turns off warnings, so that you don't get the "Spell Check Is Complete" warning and have to check "OK" to get on with business.

You stated in the other post that you wanted to check ALL boxes on the current record, and I'm working on that. Will get back to you.

Code:
Private Sub YourTextFieldName_Exit(Cancel As Integer)
With Me!YourTextFieldName
   
  [B]If Len(.Value) > 0 Then[/B]
    [B][I]DoCmd.SetWarnings False[/I][/B]
    .SelStart = 1
    .SelLength = Len(.Value)
    DoCmd.RunCommand acCmdSpelling
     .SelLength = 0
    [B][I]DoCmd.SetWarnings True[/I][/B]
  [B]End If[/B]

End With
End Sub
 
Last edited:
I MUST stress that if you EVER use DoCmd.SetWarnings, PUT AN ERROR HANDLER IN AND RESET IT TO TRUE!. I would like to see everyone who offers up the use of DoCmd.SetWarnings False post that as well. Because, if you do not put DoCmd.SetWarnings True into an error handler to reset them if an error occurs, then if your code gets past the DoCmd.SetWarnings False but fails before it sets it true again it will leave you without ANY error messages at all.
 
Good point, Bob! I'll do that in the future!
 
Last edited:
You can use the code here for each text box you want checked, Samrasr, and to honest that's what I'd probably do, but then I only do Spell Checking on memo fields. But if you want to do it on all fileds on your form, an advanced practitioner of the Art of Access has posted a function that will do this here:

http://www.tek-tips.com/viewthread.cfm?qid=1371880&page=1

It involves a bit of work, but it should do the trick in style!

Good Luck!
 
Thanks al lot

Thank you for your replys and time.

Much appreciated allways
 

Users who are viewing this thread

Back
Top Bottom