Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

compulsary information in text box

Status
Not open for further replies.

thefroggy

Technical User
Apr 20, 2004
31
GB
Hi,

I hope that someone can help me with this one.

I have a form that people fill up to enter information on suppliers; two text boxes must be filled up with information, supplier name and phone number

How can I introduce such obligation? I want to make it a bite smart, with pop up window indicating the reason of error (e.g please fill up name or phone field) and also having the cursor going automatically to the designated field.

How can it be done? Thanks in advance.

Steph
 
Hi

In your table design for the fields, validatition rule Is Not Null and validation text whatever message you want to appear
 
You can make the form in question only close from a command button, which will check the required fields with an if statement and not allow the form to close if they are null. Check out the faq702-2071 to get started.
 
If you use the solution suggested by mguidry5 you can do the same with the close button on. In the form_unload event check the fields are populated if they aren't set Cancel = True to stop the form unloading.

HarleyQuinn
---------------------------------
Help us to help you,
read FAQ222-2244 before posting.
 
Thanks for the auick reply,

- SuicidED -, I have tryied your solution, it is working but not like I want. Sorry I was not clear enough in my request.

I would like this compulsory event to be triggered when the user is trying to print or close the form.

- mguidry5 - sorry but I have started using access for little time, and I not sure I understand what I need to do, can you help me their please?

Thanks

Steph

 
theFroggy,

If you've just started using Access, then I suggest taking a look at this website first:
That will get you familiar with using VBA code much more quickly than I could. If you are familiar with code, then let me know and I can help you work it out.

Cheers,
Mike
 
mguidry5,

I'm using VBA for simple event, so I know how it works. However I'm still learning the art of creating a more complex application.

that's why I need a bite of help with your solution.

Thanks,

Steph.
 
Try something like this:
Code:
Private Sub Form_Unload(Cancel As Integer)
Text1.SetFocus
If Text1.Text = "" Then Cancel = 1 [green]'or Cancel = True[/green]
End Sub
What this does is when the form tries to unload it checks if the text in Text1 (rename this as the name of your TextBox) is blank (""). If it it it sets the cancel parameter of the unload event to 1 (True), when this happens the form will not unload. You can easily modify this to encorporate your two textboxes needed for validation.

Hope this helps

HarleyQuinn
---------------------------------
Help us to help you,
read FAQ222-2244 before posting.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top