Setting A Textbox Value In VBA Doesn't Appear To Be Triggering It's Change Event

Ark68

Well-known Member
Joined
Mar 23, 2004
Messages
4,566
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I have a commandbutton (uf8b_cancel) on my userform (uf8b_postcomm), that when pressed will clear values of a second userform (uf8_post), essentially "re-initializing" uf8_post. I don't need to actually initialize that form as during the initialization there are fields that are unachanged and would just be recalculated again.

The way I have thought to do this is to trigger a textbox change event in uf8_post by assigning that field a value.

By assigning a value to a textbox, will that trigger it's change event? As I have it now, it isn't ....

My button code from uf8b_postcomm
Code:
Private Sub uf8b_cancel_Click()
    With uf8_post               'original userform
        uf8_rin = "0"           'change textbox value forcing uf8_rin change event
    End With
    Unload uf8b_postcomm        'close this userform
End Sub

The above is supposed to change the value of uf8_post.uf8_rin (textbox) and thus forcing it's change event. The change evnt recognizes the value as being zero and clears the appropriate fields.

Code:
Private Sub uf8_rin_Change()
    Dim s_rin As String
    Dim rin As Long
    Dim t_row As Long 'target row
    
    s_rin = uf8_prin.Value & uf8_rin
    rin = s_rin * 1
    t_row = Application.WorksheetFunction.Match(rin, ws_psttemp.Range("A:A"), 0)
    If uf8_rin.Value = "0" Then
        With ws_psttemp
            uf8_rin.Value = ""
            uf8_rin.BackColor = RGB(0, 168, 232)
            uf8_tstat.BackColor = vbWhite
            uf8_d_contract = ""
            uf8_d_start = ""
            uf8_d_end = ""
            uf8_d_event = ""
            uf8_d_league = ""
            uf8_d_cust = ""
            uf8_d_fac = ""
        End With
    Else
        With ws_psttemp
            uf8_rin.BackColor = vbWhite
            uf8_tstat.BackColor = RGB(0, 168, 232)
            uf8_d_contract = .Range("F" & t_row)
            uf8_d_start = format(.Range("G" & t_row), "h:mm AM/PM")
            uf8_d_end = format(.Range("H" & t_row), "h:mm AM/PM")
            uf8_d_event = " " & .Range("L" & t_row)
            uf8_d_league = " " & .Range("M" & t_row)
            uf8_d_cust = " " & Application.WorksheetFunction.VLookup(.Range("F" & t_row), ws_rd.Range("A:K"), 11, False)
            uf8_d_fac = " " & .Range("C" & t_row) & " " & .Range("D" & t_row)
        End With
    End If
End Sub

Is this not the best approach? Or is there an error in my coding?
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
I simply missed a period ...

Rich (BB code):
Private Sub uf8b_cancel_Click()
    With uf8_post               'original userform
        .uf8_rin = "0"           'change textbox value forcing uf8_rin change event
    End With
    Unload uf8b_postcomm        'close this userform
End Sub
 
Upvote 0
Are you using Option Explicit?

If you were 'uf8_rin' would probably have been highlighted as an undeclared variable.
 
Upvote 0

Forum statistics

Threads
1,223,749
Messages
6,174,280
Members
452,554
Latest member
Louis1225

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