Custom Function

A

Abdul Shakeel

Hi All,

I've a form in which I've several text Boxes some of which are must to be
filled by the user I just want that if user dont put data in any required
textbox a custom massage appears asking for filling the data.

for this purpose I want that I make custom function so I could call this
function anywhere I want this validation.
 
K

Klatuu

The best place to ensure a value is in a required field is in the Form
Current event. The basic structure there is:

Private Sub Form_Current(Cancel As Integer)

If <<some condition fails>> Then
MsgBox "Not Valid"
Cancel = True
End If

You can do it specifically for each control you want to validate:

If IsNull(Me.txtFilingDate) Then
MsgBox "Filing Date Is Required"
Cancel = True
Me.txtFilingDate.SetFocus
End If

You could write a generic function you can call from anywhere, but
generally, the requirements for each control are unique enough that such a
function may not be that useful.
 
R

Robert Morley

I'm not seeing the problem here. Cancel is an Integer in forms (for no
reason I understand...I think it's because historically, there was no Boolean).


Rob
 
S

Stuart McCall

Robert Morley said:
I'm not seeing the problem here. Cancel is an Integer in forms (for no
reason I understand...I think it's because historically, there was no
Boolean).


Rob

Hi Rob

So you missed it too <g>.
The Form_Current event doesn't have a Cancel parameter. He'll know as soon
as he re-reads what I back-quoted. I think he probably means
Form_BeforeUpdate.
 
R

Robert Morley

Hi Rob
So you missed it too <g>.
The Form_Current event doesn't have a Cancel parameter. He'll know as soon
as he re-reads what I back-quoted. I think he probably means
Form_BeforeUpdate.

D'oh!


Rob
 

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

Similar Threads

Empty TextBox 1
Required field on form 0
Validation of Data 5
your 2 cents on this form design 3
Outlook custom forms 0
First Custom Menu 2
Access 2007 Toolbar Issue 1
For Each Object In Form... 10

Top