devxlogo

Undo Changes in Text Boxes

Undo Changes in Text Boxes

Most professional applications have an Undo menu option under the Editmenu. If you want to have an undo feature for every text box, you may thinkyou need to create a variable to hold the old value for every field. Fortunately,Windows takes care of this for you. With a call to the Windows API functionSendMessage(), you can have the old value put back into the text box. Createa menu item called Undo and add this code:

 Sub mnuUndo_Click () Call TextUndo(Screen.ActiveControl) End Sub TextUndo() is responsible for performing the undo: Declare Function SendMessage Lib "User" _ (ByVal hWnd As Integer, ByVal wMsg As Integer, _ ByVal wParam As Integer, lParam As Any) As Long Sub TextUndo (ctlControl As Control) Dim lReturn As Long Const EM_UNDO = &H417 If TypeOf Screen.ActiveControl Is TextBox Then lReturn = SendMessage(ctlControl.hWnd, _ EM_UNDO, 0, 0&) End If End Sub

Because some third-party controls also support the undo message,place TextUndo() in a separate routine to make it easy to change this onefunction by adding the Class name of the third-party control. If you do,there will be no reason to change all the calls to the SendMessage() function.

See also  Why ChatGPT Is So Important Today
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist