Ark68
Well-known Member
- Joined
- Mar 23, 2004
- Messages
- 4,570
- Office Version
- 365
- 2016
- Platform
- Windows
I have this code that calls a userform (uf_new_eqt) when the user selects "Other" from the cell's validation list.
The userforms open, and the user enters a value in textbox1. An AfterUpdate event does some error checking on the value entered, including checking the existing database to see if the value entered is already in the database. If it is, there is no need to continue with the usedform. The value entered in textbox1 is moved to the userfield in the worksheet which in turn reruns the worksheet change event for that cell.
I run into big issues though after the userform is closed.
Following the Unload Me command, I get this error:
"Automation error. The object invoked has disconnected from it's clients"
When I press Debug, it takes me to the worksheet change code where the userform was originally called (the orange line). It wants to reload the form.
If I stop the code, Excel closes and reopens with a recovered version of the workbook.
Can someone identfy the issue and help me avoid this problem.
Rich (BB code):
'EQT CHANGE
'validation is coded based on work centre and does not change
If Not Intersect(Target, Range("$M$4")) Is Nothing Then
Application.ScreenUpdating = False
mbevents = False
Unprotect
vEqt = Target.Value
'invalid entries (not trapped by validation)
'null value
'If Range("$M$4") = "" Then
'MsgBox "Please select the equipment from the dropdown." & Chr(13) & "(Select 'Other' to add equipment not in the list.)", vbCritical, "Invalid Entry [EQUIPMENT]"
'Range("M4") = "!"
'With Range("M4").Font
' .Color = vbRed
' .Italic = False
'End With
'mbevents = True
'Protect
'Application.ScreenUpdating = True
'Exit Sub
'End If
'seperator selected
If vEqt = "- - -" Then
With Range("M4")
.Value = ""
.Color = RGB(19, 65, 98)
.Italic = False
End With
mbevents = True
Protect
Application.ScreenUpdating = True
Exit Sub
End If
'other selected
If vEqt = "Other" Then
reset_svr_buttons 'serices buttons reset until they can be defined
mbevents = True
uf_new_eqt.show 'equipment entry form
Protect
Application.ScreenUpdating = True
Exit Sub
End If
'valid entry
If vEqt = "" Then
mbevents = True
Protect
Application.ScreenUpdating = True
Exit Sub
End If
Range("M4:N4").Font.Color = vbBlack
seqt = Application.WorksheetFunction.VLookup(vEqt, ws_lists.Range("E2:G36"), 2, False) 'selected equipment text
Range("O4") = seqt
'prepare start temp
Range("F7:G7").Locked = False 'unlock start temp
Range("F7:G7").Interior.Color = RGB(216, 241, 234)
'populate data range
Range("R" & dcomprow) = Range("M4")
bdr_eqt 'reset border after missing data flag
'service button determination
reset_svr_buttons 'clear all service buttons
determine_service_buttons vEqt 'activate appropriate service buttons based on equipment selection
Range("F7").Select
Protect
mbevents = True
Application.ScreenUpdating = True
End If
The userforms open, and the user enters a value in textbox1. An AfterUpdate event does some error checking on the value entered, including checking the existing database to see if the value entered is already in the database. If it is, there is no need to continue with the usedform. The value entered in textbox1 is moved to the userfield in the worksheet which in turn reruns the worksheet change event for that cell.
Rich (BB code):
Private Sub TextBox1_AfterUpdate()
'Stop
If Len(TextBox1.Value) < 2 Then
MsgBox "Enter a valid (2+ numeric characters) equipment number.", vbExclamation, "Invalid Entry [EQUIPMENT]"
TextBox1.Value = ""
If tb_tally > 0 Then tb_tally = tb_tally - 1
ElseIf IsNumeric(Me.TextBox1.Value) = False Then
MsgBox "Enter a valid (2+ numeric characters) equipment number.", vbExclamation, "Invalid Entry [EQUIPMENT]"
TextBox1.Value = ""
If tb_tally > 0 Then tb_tally = tb_tally - 1
ElseIf Application.WorksheetFunction.CountIf(ws_lists.Columns("AQ"), Me.TextBox1.Value) > 0 Then
Stop
srow = Application.WorksheetFunction.Match(CDbl(Me.TextBox1.Value), ws_lists.Columns("E"), 0)
MsgBox "Unit " & Me.TextBox1.Value & ", " & ws_lists.Cells(srow, 6) & ", exists in the database already." & Chr(13) _
& "Please select the unit from the dropdown selection.", vbInformation, "Duplication"
mbevents = True
ws_gui.Range("M4") = Me.TextBox1.Value
Unload Me
'mbevents = True
Exit Sub
Else
tb_tally = tb_tally + 1
End If
tally = cb_tally + tb_tally + hb_tally
If tb_tally = 2 And hb_tally = 1 And cb_tally > 0 Then Me.uf_eqt_submit.Enabled = True
Me.TextBox2.Locked = False
End Sub
I run into big issues though after the userform is closed.
Following the Unload Me command, I get this error:
"Automation error. The object invoked has disconnected from it's clients"
When I press Debug, it takes me to the worksheet change code where the userform was originally called (the orange line). It wants to reload the form.
If I stop the code, Excel closes and reopens with a recovered version of the workbook.
Can someone identfy the issue and help me avoid this problem.