Spell check resets listbox

G

Guest

I have a form with a textbox and a tab control (have a text box and listbox
on the tab), I have added the code below to spell check the text box on the
tab control:
Forms!responses!txtstrength.SetFocus
DoCmd.RunCommand acCmdSpelling

The code does check the spelling of the textbox on the tab control, however
it also goes to the main form and checks the spelling of the textbox there
and then it resets the selected item in the listbox on the tab control to the
first item which causes my "Update" button to update the wrong item in the
listbox.

Is there anyway to A)Stop the spell check from checking other text fields on
the main form and B)Keep the listbox item selected to stay the same as before
the spell check codes executes?

Thanks for any help or suggestions!

Jerry
 
G

Guest

Hi, Jerry.
Keep the listbox item selected to stay the same as before
the spell check codes executes?

Create two local variables in the procedure that calls the spellchecker
routine. For example:

Dim nSaveIdx As Long
Dim idx as Long

Next, add a few lines to your code that saves the index of the selected item
in the list box, then runs the spellchecker, then restores the selected item:

Forms!responses!txtstrength.SetFocus

For idx = 0 To (Me!lstBox.ListCount - 1)
If (Me!lstBox.Selected(idx)) Then
nSaveIdx = idx
End If
Next idx

DoCmd.RunCommand acCmdSpelling
Me!lstBox.Selected(nSaveIdx) = True

.. . . where lstBox is the name of the list box.

HTH.
Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips.

(Please remove ZERO_SPAM from my reply E-mail address so that a message will
be forwarded to me.)
- - -
If my answer has helped you, please sign in and answer yes to the question
"Did this post answer your question?" at the bottom of the message, which
adds your question and the answers to the database of answers. Remember that
questions answered the quickest are often from those who have a history of
rewarding the contributors who have taken the time to answer questions
correctly.
 
G

Guest

And if the list box is on another form, in the example replace:
Me!

with:

Forms!MyForm

.. . . where MyForm is the name of the other form. So the example should
look like this:

Forms!responses!txtstrength.SetFocus

For idx = 0 To (Forms!MyForm!lstBox.ListCount - 1)
If (Forms!MyForm!lstBox.Selected(idx)) Then
nSaveIdx = idx
End If
Next idx

DoCmd.RunCommand acCmdSpelling
Forms!MyForm!lstBox.Selected(nSaveIdx) = True

HTH.
Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips.

(Please remove ZERO_SPAM from my reply E-mail address so that a message will
be forwarded to me.)
- - -
If my answer has helped you, please sign in and answer yes to the question
"Did this post answer your question?" at the bottom of the message, which
adds your question and the answers to the database of answers. Remember that
questions answered the quickest are often from those who have a history of
rewarding the contributors who have taken the time to answer questions
correctly.
 
G

Guest

Thanks for the code snipit - Works great!

Any thoughts on how to stop spell check from checking other text field on
main form?

Jerry
 
M

Marshall Barton

JWS315 said:
I have a form with a textbox and a tab control (have a text box and listbox
on the tab), I have added the code below to spell check the text box on the
tab control:
Forms!responses!txtstrength.SetFocus
DoCmd.RunCommand acCmdSpelling

The code does check the spelling of the textbox on the tab control, however
it also goes to the main form and checks the spelling of the textbox there
and then it resets the selected item in the listbox on the tab control to the
first item which causes my "Update" button to update the wrong item in the
listbox.

Is there anyway to A)Stop the spell check from checking other text fields on
the main form and B)Keep the listbox item selected to stay the same as before
the spell check codes executes?


In addition to Gunny's reply, you can lisit spell check to
just look at the text box by selecting its text:

With Forms!responses!txtstrength
.SetFocus
.SelStart = 0
.SelLength = Len(.Text)
End With
DoCmd.RunCommand acCmdSpelling
 
G

Guest

Gunny & Marshall,

Fantastic!! Thanks for the quick response and help - Works great!!

Jerry
 
G

Guest

Is there anyway not to show the dialog "Spell Check Complete" when there are
NO misspelled words?

Thanks

Jerry
 
M

Marshall Barton

Not that I have come across, but then I don't mind seeing
the popup. Without that box, how would you know if the
spell check actually did anything?
 
G

Guest

I didn't think there would be but it would be nice to have the option. I
automatically check spelling on the textbox whenever the user adds a new
record so the "extra" popup dialog is another click that has to be made even
when there are no misspelled words.

Thanks for the help!

Jerry

Marshall Barton said:
Not that I have come across, but then I don't mind seeing
the popup. Without that box, how would you know if the
spell check actually did anything?
--
Marsh
MVP [MS Access]

Is there anyway not to show the dialog "Spell Check Complete" when there are
NO misspelled words?
 
M

Marshall Barton

I agree that options are nice and I can see where you're
coming from, but these DoCmd methods are just simulating a
tool bar button so they do not really have many options. At
least not anything that's been documented.

OTOH, maybe you should give Word's CheckSpelling method a
try. Here's a copy of Doug Steele's post from on 8/28/05 to
a related question.

-------------------------------------------------------------------------
Function WordSpellCheck(WordToCheck As String) As Boolean
On Error GoTo Err_WordSpellCheck

Dim wd As Object

If Len(WordToCheck) > 0 Then
Set wd = CreateObject("Word.Application")
WordSpellCheck = wd.CheckSpelling(WordToCheck)
End If

End_WordSpellCheck:
If Not wd Is Nothing Then
wd.Quit
Set wd = Nothing
End If
Exit Function

Err_WordSpellCheck:
MsgBox Err.Description
Resume End_WordSpellCheck

End Function
 
G

Guest

Marshall,

Thanks for the reference to Doug's code. I did find something that seems to
work - by setting warnings to false prior to checking spelling-

DoCmd.SetWarnings False
DoCmd.RunCommand acCmdSpelling
DoCmd.SetWarnings True

This will stop the dialog "Spell checking complete" when there are no
misspelled words and shows the appropriate spell check dialog when words are
misspelled.

Thanks for all the help!

Jerry


Marshall Barton said:
I agree that options are nice and I can see where you're
coming from, but these DoCmd methods are just simulating a
tool bar button so they do not really have many options. At
least not anything that's been documented.

OTOH, maybe you should give Word's CheckSpelling method a
try. Here's a copy of Doug Steele's post from on 8/28/05 to
a related question.

-------------------------------------------------------------------------
Function WordSpellCheck(WordToCheck As String) As Boolean
On Error GoTo Err_WordSpellCheck

Dim wd As Object

If Len(WordToCheck) > 0 Then
Set wd = CreateObject("Word.Application")
WordSpellCheck = wd.CheckSpelling(WordToCheck)
End If

End_WordSpellCheck:
If Not wd Is Nothing Then
wd.Quit
Set wd = Nothing
End If
Exit Function

Err_WordSpellCheck:
MsgBox Err.Description
Resume End_WordSpellCheck

End Function
------------------------------------------------------------
--
Marsh
MVP [MS Access]

I didn't think there would be but it would be nice to have the option. I
automatically check spelling on the textbox whenever the user adds a new
record so the "extra" popup dialog is another click that has to be made even
when there are no misspelled words.
 
M

Marshall Barton

JWS315 said:
Thanks for the reference to Doug's code. I did find something that seems to
work - by setting warnings to false prior to checking spelling-

DoCmd.SetWarnings False
DoCmd.RunCommand acCmdSpelling
DoCmd.SetWarnings True

This will stop the dialog "Spell checking complete" when there are no
misspelled words and shows the appropriate spell check dialog when words are
misspelled.


Well, I'll be ... I thought of that and said to myself -
no way that would work. Just goes to show, any idea is
worth a try.

Thanks for posting that.
 
G

Guest

Glad to be able to contribute something back!!

Marshall Barton said:
Well, I'll be ... I thought of that and said to myself -
no way that would work. Just goes to show, any idea is
worth a try.

Thanks for posting that.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top