Validation Dummy

  • Thread starter open a adobe file from a command button
  • Start date
O

open a adobe file from a command button

I have this code in beforeUpdate, but it does not work. All I want is to
force a name in the field, making it A-Z would be nice but just making give a
MsgBox saying somethings wrong is a start for me!!

Thanks

Private Sub E_Fname_BeforeUpdate(Cancel As String)
If Len(Me.E_Fname & vbNullString) = "''" Then
Cancel = True
MsgBox "Value required", vbOKOnly, "First Name Missing!!"
Me.E_Fname.SetFocus
End If
End Sub
 
J

Jeanette Cunningham

Hi,
Len is a function that returns a number data type.
When you say if Len(x) = "'"
Access can't understand
But if you say if Len(x) = 0 then
Access will understand

Jeanette Cunningham


"open a adobe file from a command button"
 
J

John W. Vinson

I have this code in beforeUpdate, but it does not work. All I want is to
force a name in the field, making it A-Z would be nice but just making give a
MsgBox saying somethings wrong is a start for me!!

You're trying to hard!

Instead of

If Len(Me.E_Fname & vbNullString) = "''" Then

just use

If Me.E_Fname & vbNullString = vbNullString Then


John W. Vinson [MVP]
 
L

Linq Adams via AccessMonster.com

You understand, don't you, that this approach (placing validation code in the
control's BeforeUpdate event) can be undone by the user simply not entering
the textbox? Perhaps the code should be in the *** form's *** BeforeUpdate
event?

As to only allowing A-Z, a-z, you can simply physically prevent the user from
entering anything else with code like this:

Private Sub YourTexboxName_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80
Case 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 96, 97, 98, 99, 100, 101
Case 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114
Case 115, 116, 117, 118, 119, 120, 121, 122
Case vbKeyDelete, vbKeyBack, vbKeyReturn, vbKeyRight, vbKeyLeft
Case vbKeySpace, vbKeyEscape
Case vbKeyHome, vbKeyEnd

KeyCode = KeyCode

Case Else
KeyCode = 0
End Select
End Sub

The special keys (such as vbKeyBack) are allowed so that the user can move
about the textbox.

This is rather cumbersome, and perhaps someone knows a shprter way of doing
this..

--
There's ALWAYS more than one way to skin a cat!

Answers/posts based on Access 2000/2003

Message posted via AccessMonster.com
 
S

Stuart McCall

Case 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80
Case 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 96, 97, 98, 99, 100, 101
Case 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114
Case 115, 116, 117, 118, 119, 120, 121, 122

PMFJI. You can write this as simply:

Case 65 To 122

Just FYI.
 
N

NotGood@All

John Hi. I put this code in the beforupdate but it still lets me bat out of
the field. I checked and the field does = Null

Private Sub E_Fname_BeforeUpdate(Cancel As Integer)
If Me.E_Fname & vbNullString = vbNullString Then
MsgBox ("Value Required"), vbOKOnly, "First Name Missing"
Me.E_Fname.SetFocus
End Sub
 
J

Jeanette Cunningham

John,
you need to set cancel to true
Private Sub E_Fname_BeforeUpdate(Cancel As Integer)
If Me.E_Fname & vbNullString = vbNullString Then
Cancel = True
MsgBox ("Value Required"), vbOKOnly, "First Name Missing"
Me.E_Fname.SetFocus
End Sub

Jeanette Cunningham
 
L

Linq Adams via AccessMonster.com

Thank you, Stuart! I knew there had to be a simpler way!

Linq

--
There's ALWAYS more than one way to skin a cat!

Answers/posts based on Access 2000/2003

Message posted via AccessMonster.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top