Using ProposedValue Validating String input field Access DB

Joined
Oct 10, 2005
Messages
7
Programming Experience
Beginner
I want to make sure that when adding a new record to the Access DB the user enters data all fields. I figured out the Integer fields but cannot find how to check the String fields. I searched the forum and could not locate anything. Any help would be appreciated. The Description field is the one I need.
VB.NET:
[FONT=Courier New][COLOR=green]' Validate input when the contents of the column changes.[/COLOR][/FONT]
[FONT=Courier New][COLOR=blue]Private[/COLOR] [COLOR=blue]Sub[/COLOR] dtNames_ColumnChanging([COLOR=blue]ByVal[/COLOR] sender [COLOR=blue]As[/COLOR] [COLOR=blue]Object[/COLOR], [COLOR=blue]ByVal[/COLOR] e [COLOR=blue]As[/COLOR] System.Data.DataColumnChangeEventArgs) [COLOR=blue]Handles[/COLOR] dtNames.ColumnChanging[/FONT]

[FONT=Courier New]  [COLOR=blue]Select[/COLOR] [COLOR=blue]Case[/COLOR] e.Column.ColumnName[/FONT]

[FONT=Courier New]    [COLOR=blue]Case[/COLOR] "fldPartNumber"[/FONT]
[FONT=Courier New]        [COLOR=blue]If[/COLOR] [COLOR=blue]Not[/COLOR] IsNumeric(e.ProposedValue) [COLOR=blue]Then[/COLOR][/FONT]
[FONT=Courier New]            MessageBox.Show("Part Number must be numeric", _[/FONT]
[FONT=Courier New]                     "Error", MessageBoxButtons.OK)[/FONT]
[FONT=Courier New]        [COLOR=blue]End[/COLOR] [COLOR=blue]If[/COLOR][/FONT]

[FONT=Courier New]     [COLOR=blue]Case[/COLOR] "fldPartDescription"[/FONT]
[FONT=Courier New]     [COLOR=blue]If[/COLOR] "fldPartDescription.ProposedValue.ToString() = "" Then[/FONT]
[FONT=Courier New]         MessageBox.Show("Part Description must be entered", _[/FONT]
[FONT=Courier New]                     "Error", MessageBoxButtons.OK)[/FONT]
[FONT=Courier New]     [COLOR=blue]End[/COLOR] [COLOR=blue]If[/COLOR][/FONT]
[FONT=Courier New]    [COLOR=green]'If Not Ischar(e.ProposedValue) Then[/COLOR][/FONT]
[FONT=Courier New]     [COLOR=green]'MessageBox.Show("Part Description must be entered", _[/COLOR][/FONT]
[FONT=Courier New]                [COLOR=green]'    "Error", MessageBoxButtons.OK)[/COLOR][/FONT]
[FONT=Courier New]     [COLOR=green]'End If[/COLOR][/FONT]

[FONT=Courier New]     [COLOR=blue]Case[/COLOR] "fldSalesPrice"[/FONT]
[FONT=Courier New]     [COLOR=blue]If[/COLOR] [COLOR=blue]Not[/COLOR] IsNumeric(e.ProposedValue) [COLOR=blue]Then[/COLOR][/FONT]
[FONT=Courier New]         MessageBox.Show("Sales Price must be numeric", _[/FONT]
[FONT=Courier New]                   "Error", MessageBoxButtons.OK)[/FONT]
[FONT=Courier New]     [COLOR=blue]End[/COLOR] [COLOR=blue]If[/COLOR][/FONT]

[FONT=Courier New]   [COLOR=blue]End[/COLOR] [COLOR=blue]Select[/COLOR][/FONT]
[FONT=Courier New][COLOR=blue]End[/COLOR] [COLOR=blue]Sub[/COLOR][/FONT]

 
Resolved

I found the answer in another book.

VB.NET:
[SIZE=2][COLOR=#0000ff]Case[/COLOR][/SIZE][SIZE=2] "fldPartDescription"
[/SIZE][SIZE=2][COLOR=#0000ff]   If[/COLOR][/SIZE][SIZE=2] e.Row.Item("fldPartDescription").ToString.Length = 0 [/SIZE][SIZE=2][COLOR=#0000ff]Then
[/COLOR][/SIZE][SIZE=2]      MessageBox.Show("Part Description must be entered", _
       "Error", MessageBoxButtons.OK)
[/SIZE][SIZE=2][COLOR=#0000ff]   End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE]

 
Glad you found the answer.
You may want to add the Trim method to eliminate the possibility of entering only spaces:
VB.NET:
If e.Row.Item("fldPartDescription").ToString.Trim.Length = 0 Then
 
Back
Top