Problem setting focus

johnsonk

Board Regular
Joined
Feb 4, 2019
Messages
172
Hi, When my code runs and it's a fail it sends the email and clears TextBox10 & 11 but I can not seem to get it to SetFocus back to TextBox10, can anyone help.


VBA Code:
Private Sub TextBox10_AfterUpdate()

TextBox10.Text = UCase(TextBox10.Text)



If TextBox1.Value = "" Or TextBox10.Value = "" Then Exit Sub



If TextBox1.Value = TextBox10.Value Then

TextBox11 = ("PASS")

TextBox10.BackColor = vbGreen

TextBox11.BackColor = vbGreen



Else



TextBox11 = ("FAIL")



TextBox10.BackColor = vbRed

TextBox11.BackColor = vbRed



Application.Speech.Speak "FAIL"



Dim sPath As String

result = MsgBox("THIS LABEL CODE DOES NOT MATCH THE PRICE SHEET", vbOKOnly + vbCritical, "WARNING")

If result = vbOK Then



Dim xOutApp As Object

Dim xOutMail As Object

Dim xMailBody As String

Dim wb As Workbook

On Error Resume Next

Set xOutApp = CreateObject("Outlook.Application")

Set xOutMail = xOutApp.CreateItem(0)

xMailBody = "WARNING" & vbNewLine & vbNewLine & _

"There has been a no match label scanning error" & vbNewLine & vbNewLine & _

"PRODUCT CODE: " & ComboBox1.Value & vbNewLine & _

"PRODUCT DESCRIPTION: " & TextBox2.Value & vbNewLine & _

"LABEL QTY SELETED: " & TextBox8.Value & vbNewLine & _

"LABEL CODE ON PRICE SHEET: " & TextBox1.Value & vbNewLine & _

"LABEL CODE SCANNED: " & TextBox10.Value



On Error Resume Next

With xOutMail

.To = "my.email.co.uk"

'.CC = "my.email.co.uk" & ";" " my.email.co.uk " & ";" & "my.email"

.Subject = "Stores label code scanning error"

.Body = xMailBody

.Attacments = ActiveSheet

.Send

End With

On Error GoTo 0

Set xOutMail = Nothing

Set xOutApp = Nothing

TextBox10.Text = ""

TextBox11.Text = ""

TextBox10.BackColor = &HFFFFFF

TextBox11.BackColor = &H80000002

TextBox10.SetFocus

End If

End If

End Sub
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
try moving TextBox10.Text = UCase(TextBox10.Text) to _BeforeUpdate of the text box
and using _Exit for the rest of the code.
Change that last TextBox10.SetFocus to Cancel=True.
The textbox comparisons will be case sensitive.
 
Upvote 0
or...
just remove TextBox10.SetFocus from this sub
and put Cancel=True in the _Exit

the issue is that you can't cancel afterupdate so it proceeds on to exit from that textbox
 
Upvote 0

Forum statistics

Threads
1,215,566
Messages
6,125,596
Members
449,238
Latest member
wcbyers

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