Required field in form, not table

Ms Kathy

Registered User.
Local time
Today, 03:19
Joined
May 15, 2013
Messages
190
Is there any way to require data into a field at the FORM level and not in the table?
 
Form_Before can be employed to force validations.
Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
    If Me.[COLOR=Blue]yourControlName [/COLOR]& vbNullString) = 0 Then
        MsgBox "This field cannot be empty. Please enter a valid value", vbCritical
        Me.[COLOR=Blue]yourControlName[/COLOR].SetFocus
        Cancel = True
    End If
End Sub
 
Where would I enter this code? At the "On Click" property?
 
I think Paul was referring to the form's Before Update event.
EDIT
That is the best place to do form validation.
 
I entered this in the form's Before Update property but nothing seems to be happening. (I seemed to have had to delete the closed parenthesis as it would not let me save)

Private Sub Form_BeforeUpdate(Cancel As Integer)
If Me.Trans_Weight & vbNullString = 0 Then
MsgBox "This field cannot be empty. Please enter a valid value", vbCritical
Me.yourControlName.SetFocus
Cancel = True
End If
End Sub
 
How about:
Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
  If Nz(Me.Trans_Weight,0) = 0 Then
     MsgBox "This field cannot be empty. Please enter a valid value", vbCritical
     Me.yourControlName.SetFocus
     Cancel = True
  End If
End Sub
 
Is this what I would enter - for multiple fields?? (Doesn't seem to be working):

Private Sub Form_BeforeUpdate(Cancel As Integer)
If Nz(Me.Trans_Weight, 0) = 0 Then
MsgBox "Weight in Pounds cannot be empty. Please enter a valid value.", vbCritical
Me.Trans_Weight.SetFocus
Cancel = True
End If
End Sub

Private Sub Form_BeforeUpdate(Cancel As Integer)
If Nz(Me.Trans_PricePerPound, 0) = 0 Then
MsgBox "Price per Pound cannot be empty. Please enter a valid value.", vbCritical
Me.Trans_PricePerPound.SetFocus
Cancel = True
End If
End Sub
 
All the English members have probably headed to pubs. :p

No; several ways, one:

Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
  If Nz(Me.Trans_Weight, 0) = 0 Then
    MsgBox "Weight in Pounds cannot be empty. Please enter a valid value.", vbCritical
    Me.Trans_Weight.SetFocus
    Cancel = True
  ElseIf Nz(Me.Trans_PricePerPound, 0) = 0 Then
    MsgBox "Price per Pound cannot be empty. Please enter a valid value.", vbCritical
    Me.Trans_PricePerPound.SetFocus
    Cancel = True
  End If
End Sub
 
That's what I needed. THANK YOU!

(and to think I'm sitting at this desk eating an apple whilst you folks are enjoying an ale?!)
 
That's what I needed. THANK YOU!

(and to think I'm sitting at this desk eating an apple whilst you folks are enjoying an ale?!)
NO NO I told you all. NOT yet but sooooooon. Can hardly wait.:cool:
 

Users who are viewing this thread

Back
Top Bottom