Troubleshooting VBA code - (1 Viewer)

Micron

AWF VIP
Local time
Today, 10:56
Joined
Oct 20, 2018
Messages
3,478
You are passing an object (the control); i.e. Public Function SpellChecker(txt As TextBox) As Boolean
I'm saying I would pass what the control contains (see note at end)

Public Function SpellChecker(strText As String) As Boolean
The million dollar question is, will its value work or do you still need .Text? I see no reason why you can't be successful with
Call SpellChecker(Me.PositionTitle) as long as the default property is what is passed (its .Value property is the default). If that didn't work I'd be surprised but would then try
Call SpellChecker(Me.PositionTitle.Value) OR assign Me.PositionTitle value to a string variable and pass that.

Note: You are using stuff I've never played with, so maybe you have a valid reason for passing the control itself. You would have to re-write your With block code if you don't pass the control. I just noticed that in there, you're invoking DoCmd.RunCommand acCmdSpelling which is something I haven't done. I also see that you are having to set the focus to the control and select the (now) Text in order to do that. I have to wonder if that's all necessary or can you just spell check the string I'm talking about passing instead.
 

dgreen

Member
Local time
Today, 09:56
Joined
Sep 30, 2018
Messages
397
Public Function SpellChecker(strText As String) As Boolean
The million dollar question is, will its value work or do you still need .Text?

So this doesn't work. Did I misinterprete what you recommended I test? Fails to compile on .setfocus (invalid or unqualified reference)
Code:
Public Function SpellChecker(strText As String) As Boolean
    On Error GoTo Err_SpellChecker
    
    If Trim(strText & " ") <> "" Then
        'Handles null, emptystring, and space or spaces
        'Only way this fails if you have not prinatble characters only ex. VBCRLF
        DoCmd.SetWarnings False
        .SetFocus
        .SelStart = 1
        .SelLength = Len(strText)
        DoCmd.RunCommand acCmdSpelling
        txt.SelLength = 0
        DoCmd.SetWarnings True
    End If
 

Micron

AWF VIP
Local time
Today, 10:56
Joined
Oct 20, 2018
Messages
3,478
You would have to re-write your With block code if you don't pass the control.
Please read carefully the comments and advice you are given. When they are lacking, that's on us. When they're not....
If that was read but not understood, then that would be a case for seeking clarification.
You can't have a With block when there's no longer an object.
 

Users who are viewing this thread

Top Bottom