Skipping validation in a particular circumstance

RayG

New member
Local time
Today, 21:15
Joined
Jul 1, 2005
Messages
9
Hi,

I have a bound data entry form which has a control for a file name. The control's LostFocus event incorporates a procedure to check that the named file actually exists. If the file doesn't exist, a modal form is popped up giving the user a number of options.

In most cases the file name can be derived from other data, the control can be pre-filled and the user simply tabs through. However, in some cases the file name is too complex to be derived automatically. To provide for this situation I've provided a button which runs a procedure to open the standard Windows file selector. The user makes a selection and the control is populated.

The problem is, how to skip the validation when the user clicks the file selector button but to run the validation when the focus is moved to any other control.

Thanks in advance for your suggestions,

Ray
 
Do you really want to skip validation.?
From what you are saying it will either be a filename that exists or a calculated value.?
 
Gentlemen, thanks for your responses.

Yes, I'm aware that validation is more usually carried out in the BeforeUpdate event. I guess the use of LostFocus is an historic anomaly. I'm also aware that BeforeUpdate is cancellable whereas LostFocus is not. However, it's not the event that I want to cancel but just to skip the code associated with it. I orginally included the condition:

If Not Screen.ActiveControl.Name = "btnFileSelector" then
'file checking procedure
End if

However, even though the user has clicked on the File Selector button, the active control remains the File Name control, so the procedure still runs.

Let me elucidate a little further on the process:
1 The user enters some basic data
2 The application determines the likely file name, populates the file name control and sets the focus to it.
3 The user recognizes that the file name is wrong in this instance, and clicks the File Select button.
4 The File Name control LostFocus event kicks in and irritates the user by telling him the file doesn't exist which of course they already knew!

It's this last step I'm trying to avoid whilst still keeping the file check in other circumstances.

Ray
 
Please excuse my ignorance, but how can a user select a file if it does not exist.?
Either you calculate a filename that you will create or the user selects a file.?

If you calculate a filename, can't you create it there and then?, or set a flag to to do so.?
If so, you can use that flag to determine the validation.?

From what you have said, I'd even go so far as to disable the control and either populate it via my calculation or the user file selection.

If unable to calculate, inform the user to use the button.?, either way there should be something in that control which is valid by either method.?
 
The problem with using the lost focus event is that it fires before you know what the next control is. Why not leave the user alone until they're done with the record? I might use your event to highlight the control to call attention to the fact that it needs attention.
 
then don't use Screen.ActiveControl.
use a module-wise variable:

Option Compare Database
Option Explicit

Dim m_Control As String

If m_Control <> "btnFileSelector" Then
'file checking procedure
m_Control = "btnFileSelector"
End If

***
use the Current_Event of the Form to reset m_Control to vbNullString.
 
I'm with Arnel on this one. In essence, set a flag in whatever is the "approved" method that can bypass your checks, but CLEAR the flag anywhere else (or just clear it on the Current event and don't set it elsewhere.) Then use an IF/THEN/ELSE/END IF construct to run or not run your validation.
 
Thanks for your various replies - most helpful in thinking through the problem.

Here's what I've done:
Set up a public variable 'blnFileCheck Failed'. The file check runs on exiting the File Name control. If it's successful, blnFileCheckFailed is set to false. If the check fails, the variable is set to true. The File Select button ignores the variable but every other control checks it and if it's true opens the Options dialogue form. The Options dialogue form resets blnFileCheckFailed to false, so the user will only see the form once.

Perhaps not the most elegant of solutions but I think it works.

Ray
 

Users who are viewing this thread

Back
Top Bottom