To get a error MsgBox to appear

  • Thread starter Thread starter Bob
  • Start date Start date
B

Bob

If you enter something other than a number , I want a message box to
apperar:
MsgBox "You Must enter a number from 0-100", vbApplicationModal +
vbInformation + vbOKOnly
Thanks for any help with this.......Bob

Private Sub tbOwnerPercent_AfterUpdate()
If Len([tbOwnerPercent]) = 0 Then
Exit Sub
End If
tbOwnerPercent.value = CSng(val(tbOwnerPercent.value) / 100)
End Sub
 
Hi Bob

The BeforeUpdate event is the best for validating data input:

Private Sub tbOwnerPercent_BeforeUpdate(Cancel As Integer)
If not IsNumeric(tbOwnerPercent) Then
Cancel = true
ElseIf (tbOwnerPercent<1 or tbOwnerPercent>100) _
and (tbOwnerPercent<>0) Then
Cancel = true
End If
If cancel <> 0 then
MsgBox "You Must enter a number from 1-100, or 0", vbInformation
End If
End Sub
 
Or if it's a bound field you could enter Data validation on table level..
--
Maurice Ausum


Graham Mandeno said:
Hi Bob

The BeforeUpdate event is the best for validating data input:

Private Sub tbOwnerPercent_BeforeUpdate(Cancel As Integer)
If not IsNumeric(tbOwnerPercent) Then
Cancel = true
ElseIf (tbOwnerPercent<1 or tbOwnerPercent>100) _
and (tbOwnerPercent<>0) Then
Cancel = true
End If
If cancel <> 0 then
MsgBox "You Must enter a number from 1-100, or 0", vbInformation
End If
End Sub

--
Good Luck :-)

Graham Mandeno [Access MVP]
Auckland, New Zealand

Bob said:
If you enter something other than a number , I want a message box to
apperar:
MsgBox "You Must enter a number from 0-100", vbApplicationModal +
vbInformation + vbOKOnly
Thanks for any help with this.......Bob

Private Sub tbOwnerPercent_AfterUpdate()
If Len([tbOwnerPercent]) = 0 Then
Exit Sub
End If
tbOwnerPercent.value = CSng(val(tbOwnerPercent.value) / 100)
End Sub
 
Thanks Graham , Good to know none of my owners are going to have a Blank
percent in a Horse ;) ....Bob
Graham Mandeno said:
Hi Bob

The BeforeUpdate event is the best for validating data input:

Private Sub tbOwnerPercent_BeforeUpdate(Cancel As Integer)
If not IsNumeric(tbOwnerPercent) Then
Cancel = true
ElseIf (tbOwnerPercent<1 or tbOwnerPercent>100) _
and (tbOwnerPercent<>0) Then
Cancel = true
End If
If cancel <> 0 then
MsgBox "You Must enter a number from 1-100, or 0", vbInformation
End If
End Sub

--
Good Luck :-)

Graham Mandeno [Access MVP]
Auckland, New Zealand

Bob said:
If you enter something other than a number , I want a message box to
apperar:
MsgBox "You Must enter a number from 0-100", vbApplicationModal +
vbInformation + vbOKOnly
Thanks for any help with this.......Bob

Private Sub tbOwnerPercent_AfterUpdate()
If Len([tbOwnerPercent]) = 0 Then
Exit Sub
End If
tbOwnerPercent.value = CSng(val(tbOwnerPercent.value) / 100)
End Sub
 
Have something on Sand Hawk next Saturday ellerslie....Bob

Graham Mandeno said:
Hi Bob

The BeforeUpdate event is the best for validating data input:

Private Sub tbOwnerPercent_BeforeUpdate(Cancel As Integer)
If not IsNumeric(tbOwnerPercent) Then
Cancel = true
ElseIf (tbOwnerPercent<1 or tbOwnerPercent>100) _
and (tbOwnerPercent<>0) Then
Cancel = true
End If
If cancel <> 0 then
MsgBox "You Must enter a number from 1-100, or 0", vbInformation
End If
End Sub

--
Good Luck :-)

Graham Mandeno [Access MVP]
Auckland, New Zealand

Bob said:
If you enter something other than a number , I want a message box to
apperar:
MsgBox "You Must enter a number from 0-100", vbApplicationModal +
vbInformation + vbOKOnly
Thanks for any help with this.......Bob

Private Sub tbOwnerPercent_AfterUpdate()
If Len([tbOwnerPercent]) = 0 Then
Exit Sub
End If
tbOwnerPercent.value = CSng(val(tbOwnerPercent.value) / 100)
End Sub
 
Back
Top