I have a UF that has a TextBox and some CommmandButtons.
The form is used to allow the amending of an entry is a list.
The process is
This was working as expected but after some tweaks (which I unfortunately do not know what I have tweaked), as the UF is shown, the TextBox AfterUpdate event code executes.
The code to load and populate the form is below
TextBox code
Whilst I know of a way to 'fix' this in a way that exits the AfterUpdate evenet code at the point of the UF being first shown, I know that this shouldn't be happening and I'd rather resolve the cause rather than implementing something to ignore it.
I can share the file as it is still an early dev so nothing confidential is included.
TIA
The form is used to allow the amending of an entry is a list.
The process is
Form is loaded
The entry to be amended is established
The TextBox is populated with the entry to be amended
The UF is shown
This was working as expected but after some tweaks (which I unfortunately do not know what I have tweaked), as the UF is shown, the TextBox AfterUpdate event code executes.
The code to load and populate the form is below
VBA Code:
'--------The user right-clicks a cell and there is an option to Amend Driver which fires this code
Sub AmendDriver()
boolCancel = False
Set rngHeader = Range("Drivers_Header")
strDriver = ActiveCell
Load frmDriver
boolAmend = True
Set rngListCheck = Range("D_DriversList")
With frmDriver
.Caption = "AMEND DRIVER"
.txtDriver = strDriver
.btnAdd.Caption = "AMEND"
boolAmend = False
.Show
'------When I step through the code, the UF is displayed with no issue
'------When I let the code execute whithout stepping through, the .txtDriver_AfterUpdate() code executes (see below) straight after .Show
End With
frmDriver.Hide
Unload frmDriver
If boolCancel = True Then
Exit Sub
Else
End If
Set rngAdd = Range("Drivers_Start")
Do Until rngAdd = strDriver
Set rngAdd = rngAdd.Offset(1, 0)
Loop
rngAdd = strDriverAmend
Set rngAdd = Nothing
ActiveSheet.Unprotect Password:=strPassword
MsgBox ("The Driver details have been amended"), vbInformation, "AMENDED"
End Sub
TextBox code
VBA Code:
Private Sub txtDriver_AfterUpdate()
boolTrim = True
txtDriver = Trim(txtDriver)
boolTrim = False
Set rngListCheck = Range("D_DriversList")
If boolAmend = True Then
strDriverAmend = Application.Proper(txtDriver)
If strDriverAmend = "" Then
Else
If WorksheetFunction.CountIf(rngListCheck, strDriverAmend) > 0 Then
MsgBox ("This DRIVER already exists and cannot be added"), vbExclamation, "ERROR"
boolDuplicate = True
Else
boolDuplicate = False
End If
End If
Else
strDriver = Application.Proper(txtDriver)
If strDriver = "" Then
Else
If WorksheetFunction.CountIf(rngListCheck, strDriver) > 0 Then
MsgBox ("This DRIVER already exists and cannot be added"), vbExclamation, "ERROR"
boolDuplicate = True
Else
boolDuplicate = False
End If
End If
End If
CheckAdd
End Sub
Whilst I know of a way to 'fix' this in a way that exits the AfterUpdate evenet code at the point of the UF being first shown, I know that this shouldn't be happening and I'd rather resolve the cause rather than implementing something to ignore it.
I can share the file as it is still an early dev so nothing confidential is included.
TIA