Assume we have an application that only allows access for particular users.How are we going to check that a user is actually allowed to use the application?Other tools to help your users would be using a logical tab order within the form and use combo or list boxes to restrict users choices for particular fields.HTH, Andrew If you are validating a number of fields, the easiest way to do it is in the Before Update event of the form.Denis Thanks Denis, This code appears to do what I need except the form is still closing (without saving the change) rather than staying open and moving the focus to the "offending" field. Close ac Form, "frm Projects", ac Save Yes Exit_cmd Closefrm Projects_Click: Exit Sub Err_cmd Closefrm Projects_Click: Msg Box Err.This is my code: = 3 Then If Is Null([Delivery_Finish]) Or Is Null([Delivery_Start]) Then Msg Box "This project is beyond the Shaping phase," _ & vb Cr Lf & "You must enter both delivery start & finish dates before saving! Description Resume Exit_cmd Closefrm Projects_Click End Sub Thanks once again Denis you are a life saver!In this article we will look at several methods of validating user input. It is necessary for both security reasons and also for the smooth running of your Microsoft Access application.
The methods that I covered here are generic and can easily be adjusted to use on the web. He has made many contributions to various online websites dedicated to web development.
I would like to add validation to most of these fields so they can't enter anything illogical e.g.
there is a field for Current Phase (of the Project) and I would like to ensure that, if they select "Delivery" as the current phase, they have also filled in a date in the Delivery Date field.
I’ve created a (login) form with the following design: The idea is that when a user tries to access the application, they will be confronted with the above screen that will check if they are actually allowed to use your application. Record Count 0 Then 'user does exist in database Msg Box "You can access the application" Else 'user does not exist Msg Box "Your login details do not match" End If 'recordcount recset. Close Set con = Nothing Set recset = Nothing End If As you can see in the code, the first check that is made is to see if the user has entered data into the required fields and that the data that they entered is of the right type for instance the username should not be alphanumeric or numeric it should be text.
So the user enters their login info and clicks on the submit button which runs code that looks something like this: Dim err As Boolean Dim con1 As ADODB. Recordset Dim str SQL As String 'check that the user enter something txtu Name. Text = "" Then Msg Box "Please enter all required information." err = True End If 'check that the user entered valid data i.e non-numerical txt Upass. So a check is made to ensure that the username is indeed text: A common mistake that programmers make in this kind of check is to actually state the expected length of a password in the error message box.