Change Dates With Plus and Minus Keys

Change Dates With Plus and Minus Keys

This simple piece of code saves a lot of headaches when it comes to altering dates. It allows you to use the plus and minus keys to increment and decrement date values easily. This example assumes there is a textbox named Text1 on a standard VB form:

 Private Sub Form_Load()	' Make sure that there is a valid date in Text1.	Text1.Text = DateEnd SubPrivate Sub Text1_KeyPress(KeyAscii As Integer)	' Pass handling to generic routine.	KeyAscii = DateHandler(KeyAscii)End SubPrivate Function DateHandler(KeyAscii As _	Integer) As Integer	Dim nRet As Integer	' This routine adds or subtracts days, based on the 	' key pressed, from a date value found in the control 	' represented by the form's ActiveControl property 	' (usually a TextBox). The routine can be altered to 	' add and subtract months and years too.	On Error GoTo ErrorHandler	' Constants which represent the '+' & '-' keys.	Const KeyAdd = 43	Const KeySubtract = 45	' This constant is here because '+' & '=' are on the 	' same key for most keyboards, but are sometimes inverted.	Const KeyEquals = 61' Determine the value of the key pressed, and 	' take the necessary action.	Select Case KeyAscii		Case KeyAdd, KeyEquals			Me.ActiveControl.Text = DateAdd("d", _				1, Me.ActiveControl)			nRet = 0		Case KeySubtract			Me.ActiveControl.Text = DateAdd("d", _				-1, Me.ActiveControl)			nRet = 0		Case Else			nRet = KeyAscii	End Select	' Move the start position to the end of the 	' text for a cleaner look.	If nRet = 0 Then		Me.ActiveControl.SelStart = Len(Text1.Text)	End If	' Return a new KeyAscii value.	DateHandler = nRet	Exit FunctionErrorHandler:	DateHandler = 0	Exit FunctionEnd Function
Share the Post:
XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved

AI is revolutionizing fraud detection

How AI is Revolutionizing Fraud Detection

Artificial intelligence – commonly known as AI – means a form of technology with multiple uses. As a result, it has become extremely valuable to a number of businesses across

AI innovation

Companies Leading AI Innovation in 2023

Artificial intelligence (AI) has been transforming industries and revolutionizing business operations. AI’s potential to enhance efficiency and productivity has become crucial to many businesses. As we move into 2023, several

data fivetran pricing

Fivetran Pricing Explained

One of the biggest trends of the 21st century is the massive surge in analytics. Analytics is the process of utilizing data to drive future decision-making. With so much of

kubernetes logging

Kubernetes Logging: What You Need to Know

Kubernetes from Google is one of the most popular open-source and free container management solutions made to make managing and deploying applications easier. It has a solid architecture that makes

ransomware cyber attack

Why Is Ransomware Such a Major Threat?

One of the most significant cyber threats faced by modern organizations is a ransomware attack. Ransomware attacks have grown in both sophistication and frequency over the past few years, forcing

data dictionary

Tools You Need to Make a Data Dictionary

Data dictionaries are crucial for organizations of all sizes that deal with large amounts of data. they are centralized repositories of all the data in organizations, including metadata such as