LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 137
Default Field Data Validation in VBA Forms - Here's a way

Whilst VBA forms do not support data validation on field entry, here's
some code to buidl your own. This code validates input against a field
called AssetNoInput (Asset Number Input Field) and looks for the format
AA-99999 (Two Alpha (Uppercase), a "Dash", 5 Numeric) - Max of 8
characters.

You can change the CASE statements for your own requirements.

- - - - - - - - - -

Dim xAssetNoInput

Private Sub AssetNoInput_Change()

AssetNoInput = UCase(AssetNoInput)
For Count = 1 To Len(AssetNoInput)
Select Case Count
Case 1, 2
If InStr("ABCDEFGHIJKLMNOPQRSTUVWXYZ", Mid(AssetNoInput,
Count, 1)) = 0 Then
AssetNoInput = xAssetNoInput
Beep
End If
Case 3
If Mid(AssetNoInput, Count, 1) < "-" Then
AssetNoInput = xAssetNoInput
Beep
End If
Case 4 To 8
If InStr("0123456789", Mid(AssetNoInput, Count, 1)) = 0 Then
AssetNoInput = xAssetNoInput
Beep
End If
Case 9
AssetNoInput = xAssetNoInput
Beep
End Select
Next
xAssetNoInput = AssetNoInput
CheckAssetOK
End Sub

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Data Validation/Forms Combo Box olrustyxlsuser Excel Discussion (Misc queries) 5 May 21st 07 06:49 PM
Data Validation and Forms Marge Excel Discussion (Misc queries) 3 January 30th 07 04:52 PM
data validation and forms Gary Keramidas Excel Programming 3 February 10th 06 04:42 AM
Compile/Analyze Word Form Field data from multiple forms? jgundel Excel Discussion (Misc queries) 3 July 14th 05 02:54 AM
Forms Toolbar vs. Control Toolbox vs. Data Validation for drop dow Scott Excel Discussion (Misc queries) 1 February 1st 05 01:51 PM


All times are GMT +1. The time now is 06:53 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"