Recognize Label_Click from TextBox_Exit

breynolds0431

Active Member
Joined
Feb 15, 2013
Messages
303
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I have a userform that will write the input data to a sheet after each textbox_exit. I did this to avoid having a Submit and Cancel button. The textbox_exit will check spelling (just copies contents to a sheet cell and runs .CheckSpelling on that range. I also have a label that once clicked with write a signoff to the sheet where the texbox_exit edits are made. If an edit is made to the textbox after a signoff, the signoff will be cleared - this is actually done through a worksheet_change specific to the row being edited.

Here's the problem... If a user is in a textbox and makes no changes but uses the mouse to click the signoff image, then the .CheckSpelling process will still run creating an edit and clearing the signoff. It basically writes the signoff info and then deletes it after the spell check finishes.

Below is the spell check for the textbox_exit and the img_click for the signoff. Is there a way to recognize when img_Click occurs from the textbox_exit so the .CheckSpelling doesn't run?

VBA Code:
Private Sub tbComments_Exit(ByVal Cancel As MSForms.ReturnBoolean)

Dim dSheet As Worksheet: Set dSheet = ThisWorkbook.Sheets("UDR SOIs")
Dim sCheck As Worksheet: Set sCheck = ThisWorkbook.Sheets("SpellCheck")
    Application.ScreenUpdating = False
    With sCheck
          .Range("C2").Value = Me.tbComments
          .Range("C2").CheckSpelling SpellLang:=1033
          Me.tbComments = .Range("C2").Value
          .Range("C2").ClearContents
     End With

Dim lRow As Long: lRow = dSheet.Cells(dSheet.Rows.Count, "A").End(xlUp).Row
Dim sRange As Range
Dim FindRow As Range
Set sRange = dSheet.Range(dSheet.Cells(15, 1), dSheet.Cells(lRow, 1))
Set FindRow = sRange.Find(Me.cbNoteNo, LookIn:=xlValues, lookat:=xlWhole)

If Me.cbNoteNo.Value = "" Then
     Application.ScreenUpdating = True
     Exit Sub
Else
     With dSheet
          .Unprotect
          .Cells(FindRow.Row, 7).Value = Me.tbComments
          .Protect
     End With
End If

Application.ScreenUpdating = True
End Sub

Private Sub imgL2_Click()

If Me.cbNoteNo.Value = "" Then Exit Sub

Dim dSheet As Worksheet: Set dSheet = ThisWorkbook.Sheets("UDR SOIs")
Dim lRow As Long: lRow = dSheet.Cells(dSheet.Rows.Count, "A").End(xlUp).Row

Dim sRange As Range
Dim FindRow As Range
Set sRange = dSheet.Range(dSheet.Cells(15, 1), dSheet.Cells(lRow, 1))
Set FindRow = sRange.Find(Me.cbNoteNo, LookIn:=xlValues, lookat:=xlWhole)
Dim fRow As Long: fRow = FindRow.Row

With dSheet
     .Unprotect
     .Cells(fRow, 10).Value = Environ("username") & " " & format(Now, "mm/dd/yy")
     .Protect
End With

Unload Me

End Sub
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Is there a way to recognize when img_Click occurs from the textbox_exit so the .CheckSpelling doesn't run?
I'm going to say no (based on my knowledge of Access vba and form events). Once an event is over it leaves no trace unless you create one. So the exit event terminates and code for the next event runs when the next event occurs, but it has no 'knowledge' of the event that preceded it.

Not clear if by 'no change' you mean nothing was entered or if that means the entry was clicked on but not changed, but that's what this suggestion is based on:
Based on your current approach, have module level variables to hold the textbox values that you assign at the beginning of the event code. Check them for values and if the variable value is the same as the current textbox value, don't run the spell check.

If you meant the problem is when there is nothing in one or more textboxes, then don't run the spell check? Methinks I'd put that code by itself and do/don't call it rather than trying to decide to run it or bypass it.
 
Upvote 0

Forum statistics

Threads
1,214,641
Messages
6,120,695
Members
448,979
Latest member
DET4492

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top