SubForm memo field - Spell Check (1 Viewer)

evictme

Registered User.
Local time
Today, 10:44
Joined
May 18, 2011
Messages
168
Hello All,

Back again with a new problem I hope you can help me with:

I have a Form that has onload event LockBoundControls with a subform for notes.

I am trying to add spell check feature to the notes field in the subform, which is a memo field, but I keep getting the error message:

2046: command or action Spelling isnt available now

Here is the code I am trying in the OnExit event field:

If Len(Me.Notes & "") > 0 Then
DoCmd.RunCommand acCmdSpelling
Else
Exit Sub
End If

Any help would be greatly appreciated.

Form [Client] Subform [ClientNotes] linked by [ClientID]
 

missinglinq

AWF VIP
Local time
Today, 11:44
Joined
Jun 20, 2003
Messages
6,423
A Subform is a Control on the Main Form...so if LockBoundControls does what it says...i.e. locks all Bound Controls...the Subform is Locked and you could neither enter data nor Spell Check it.

You'd need to lock all Controls except the Subform Control to do this...unless I'm misinterpreting your scenario.

Linq ;0)>
 

evictme

Registered User.
Local time
Today, 10:44
Joined
May 18, 2011
Messages
168
I understand that. I have a button that locks/unlocks the form. Essentially what happens is the form loads, locked, the user unlocks to edit (including the subform) and theyre good to go.

Despite being unlocked and the subform allowing for edits I am unable to get the code to work. It just wont allow for spelling. Whats interesting is that if I move the cursor to a field in the Form Access will provide the option to spell check in the menu bar but not in that field.

What am i missing here?
 

evictme

Registered User.
Local time
Today, 10:44
Joined
May 18, 2011
Messages
168
The fileds in question were set to Plain Text and have now changed them to Rich Text but despite this the cmdSpelling option is not available for the field.

Any help would be greatly appreciated.
 

CJ_London

Super Moderator
Staff member
Local time
Today, 16:44
Joined
Feb 19, 2013
Messages
16,610
think you need to select the text for accmdspelling to work

investigate the selstart and sellength properties to do this with vba
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 23:44
Joined
May 7, 2009
Messages
19,230
what code do you have to lock the bound controls and the subform?
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 11:44
Joined
Feb 19, 2002
Messages
43,233
Here are some code snippits from one of my apps. I've included the code to check a single field as well as the code to check all fields on a form and I've included a sample calling code procedure.

In theory, there is no reason to check existing data or data that hasn't been changed so the spellcheck would normally be called from the form's BeforeUpdate event. Please let me know if I've missed anything you need.

Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)

    If Forms!frmLogin!chkOKPlanNotes = True Then
    Else
        MsgBox "You are not authorized to enter or change notes.", vbOKOnly
        Me.Undo
        Cancel = True
        Exit Sub
    End If
    
    If Me.NewRecord = False Then
        Select Case True
            Case DateDiff("h", Me.ChangeDT, Now()) <= 24 And Forms!frmLogin!txtEmpID = Nz(Me.ChangeBy, Forms!frmLogin!txtEmpID)
                'update allowed
            Case Forms!frmLogin!chkISSPV = True
                'update allowed
            Case Else
                MsgBox "Notes may only be changed by the person who made the entry (within 24 hours) or by a Supervisor.", vbOKOnly
                Me.Undo
                Cancel = True
                Exit Sub
        End Select
    End If
    
    If Not IsDate(Me.txtReferenceDT) Then
        MsgBox "Reference date is required.", vbOKOnly
        Me.txtReferenceDT.SetFocus
        Cancel = True
        Exit Sub
    End If
    If Me.cboNotesTypeID & "" = "" Then
        MsgBox "Notes Type is required.", vbOKOnly
        Me.cboNotesTypeID.SetFocus
        Cancel = True
        Exit Sub
    End If
    If Me.txtNoteText & "" = "" Then
        MsgBox "Note text is required.", vbOKOnly
        Me.txtNoteText.SetFocus
        Cancel = True
        Exit Sub
    End If
    If Me.cboEmpID & "" = "" Then
        MsgBox "Taken By is required.", vbOKOnly
        Me.cboEmpID.SetFocus
        Cancel = True
        Exit Sub
    End If
    
    
    Call cmdSpell_EntireForm(Me)
    
    Me.ChangeBy = Forms!frmLogin!txtEmpID
    Me.ChangeDT = Now()
End Sub



Public Sub cmdSpell_EntireForm(frm)
   Dim ctlSpell As Control
   Dim ctlName As String

   On Error GoTo Err_Proc

   DoCmd.SetWarnings False
   ' Enumerate Controls collection.
   
   For Each ctlSpell In frm.Controls
     If TypeOf ctlSpell Is TextBox Then
       If Len(ctlSpell) > 0 Then
         With ctlSpell
           .SetFocus
           .SelStart = 0
           .SelLength = Len(ctlSpell)
         End With
         DoCmd.RunCommand acCmdSpelling
         If ctlName = ctlSpell.name Then
            GoTo Exit_Proc
         Else
            ctlName = ctlSpell.name
         End If
       End If
     End If
   Next
   DoCmd.SetWarnings True

Exit_Proc:
   On Error GoTo 0
   Exit Sub

Err_Proc:

    Select Case Err.Number
        Case Else
            MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure cmdSpell_EntireForm of Module mSpellCheckForRuntime"
    End Select
 End Sub

Public Sub cmdSpell_SingleControl(cntl As Control)
    Dim ctlSpell As Control
    
   On Error GoTo Err_Proc

    Set ctlSpell = cntl 'Screen.PreviousControl
    If IsNull(Len(ctlSpell)) Or Len(ctlSpell) = 0 Then
        'MsgBox "There is nothing to spell check."
        'ctlSpell.SetFocus
        Exit Sub
    End If
            
    DoCmd.RunMacro "mWarningsOff"        'turn warnings off to surpress "complete" message
    With ctlSpell
      .SetFocus
      .SelStart = 0
      .SelLength = Len(ctlSpell)
    End With
    DoCmd.RunCommand acCmdSpelling
    DoCmd.RunMacro "mWarningsOn"

Exit_Proc:
   On Error GoTo 0
   Exit Sub

Err_Proc:

    Select Case Err.Number
        Case Else
            MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure cmdSpell_SingleControl of Module mSpellCheckForRuntime"
    End Select
 End Sub
 

Users who are viewing this thread

Top Bottom