Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 01-28-2022, 12:02 PM
DrTyDawg DrTyDawg is offline If/Else clear current activex textbox Windows 10 If/Else clear current activex textbox Office 2016
Novice
If/Else clear current activex textbox
 
Join Date: Jan 2022
Posts: 2
DrTyDawg is on a distinguished road
Default If/Else clear current activex textbox

I have a table in a word document macro-enabled template. Each cell has an ActiveX TextBox in it. In one specific column, I only want to accept numerical characters. If a user enters anything else, a message box pops up informing the user that this is an error.





I would also like to have the non-conforming text be deleted, or the last action to be undone. Unfortunately whatever is typed into an ActiveX control is not registered in the undo table so "Undo" doesn't work. This is my code.



Brief Explanation: Cell 1 is the column title and is not changed (named QTY). Each ActiveX TextBox is in cells 2-20 in the column and is named txtQty#. This is where you enter in numbers only. Cell 21 is the Total value of the numbers entered in cells 2-20 and is named txtTotalQty.


Code:
Private Sub QtyChanged(newValue As String)

    If Trim(newValue) <> "" And Not IsNumeric(newValue) Then
    
 'Display a pop-up message
 MsgBox "This cell only accepts numerical values. Please make the correction before proceeding", vbOKOnly, "ERROR!"
 
    Else
        With Me
            txtTotalQty.Text = Format(Val(.txtQty1.Value) + Val(.txtQty2.Value) + Val(.txtQty3.Value) + Val(.txtQty4.Value) + Val(.txtQty5.Value) + Val(.txtQty6.Value) + Val(.txtQty7.Value) + Val(.txtQty8.Value) + Val(.txtQty9.Value) + Val(.txtQty10.Value) + Val(.txtQty11.Value) + Val(.txtQty12.Value) + Val(.txtQty13.Value) + Val(.txtQty14.Value) + Val(.txtQty15.Value) + Val(.txtQty16.Value) + Val(.txtQty17.Value) + Val(.txtQty18.Value) + Val(.txtQty19.Value), "#,##0")
        End With
    End If
    
End Sub

Ideally the solution should involve the current actively selected ActiveX TextBox control being completely cleared after the user clicks "OK" on the error message to dismiss it.
Reply With Quote
 

Tags
activex control, textbox, undo



Similar Threads
Thread Thread Starter Forum Replies Last Post
Event macro: insert row with formulae based on current row, clear selected contents emsa Excel Programming 5 04-17-2020 09:03 AM
If/Else clear current activex textbox How to track changes in a ActiveX Textbox tommasorossotti Word VBA 1 02-24-2020 03:57 AM
If/Else clear current activex textbox ActiveX Textbox properties using VBA kyeung Word VBA 5 10-05-2015 12:47 AM
If/Else clear current activex textbox Display result in textbox based on the input of another textbox scarymovie Word VBA 5 05-16-2012 07:05 PM
How to insert a hyperlink in activex textbox Joe Patrick Word VBA 1 10-03-2011 06:03 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 09:48 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft