Msg Boxes in Forms

KristenD

Registered User.
Local time
Yesterday, 22:07
Joined
Apr 2, 2012
Messages
394
For my database that I have created I have a main form which all the other subforms in the tabs are related to. The main form is based off the employee information.

I was wondering if in certain tab controls with certain forms if I could have kind of like a double check for me (since I am the only one doing entry in the program, the other users will just be running reports and exports) based on certain data that is input.

For example, if the employee status is Active in the main form. And in the form I am currently working on is OSHA training there is a field for a job number. If I happen to forget to input that job number is there a way I can write something so Access pops up a message box saying This employee is active you need to enter a job number before continuing. The tables are related by the employee id which is included in both forms as well as the relationship between the tables.

Thank you in advance!!
 
use the FORM's before update event

one of these, depending on whether the value is numeric or not

Code:
if nz(somefield,"") = ""
if nz(somefield,0) = 0

use it in this way

Code:
if nz(somefield,"") = "" then
 msgbox("Please enter a value for somefield")
  somefield.setfocus
  cancel = true
end if

adding cancel = true prevents the record being saved, until you satisfy the condititon.

or

Code:
if nz(somefield,"") = "" then
  msgbox("Reminder. You need to enter a value for somefield")
 
 
end if

this just warns without actually preventing the save.


-----
when it comes to validation - eg making sure a textbox vlaue is unique you have a couple of options

a) in the CONTROL's before update, do a dlookup, or similar to see if the value has been used.

b) do it in the FORM's before update event - or even just rely on access table constraints preventing the error.

the trouble with b) is that it is not very user-friendly. you get to the end of the record then find out you already entered the value!

------
note that even when you do stuff for yourself, you are likely to spend a lot of time coding defensive stuff like this.
 
Awesome!!! Thank you SO much!!!
 
Sorry stupid question but which form do I enter the code in?

Main form or the tabbed form?

I just did it in the tabbed form and nothing happened.
 

Users who are viewing this thread

Back
Top Bottom