Blocking fields from being updated unless other fields have been entered first (1 Viewer)

TobyMace

Registered User.
Local time
Today, 23:09
Joined
Apr 13, 2018
Messages
65
Hi,

Is there a way I can keep the focus on the current control if an If statement is false? But if true move to another field?

I currently have:

Code:
Private Sub TestStage_AfterUpdate()

If Unit_Type <> "SP2240" And TestStage = "ESSPASS" And PreESS_FTP = "NO" Then
MsgBox "My text"
TestStage.SetFocus
End If

If Unit_Type <> "SP2240" And TestStage = "ESSFAIL" And PreESS_FTP = "NO" Then
MsgBox "My text"
TestStage.SetFocus
End If

If Unit_Type <> "SP2240" And TestStage = "ESSPASS" And PreESS_FTP = "YES" Then
ESS_FTP = "YES"
ESS_Tested = "YES"
User.SetFocus
End If

If Unit_Type <> "SP2240" And TestStage = "ESSFAIL" And PreESS_FTP = "YES" Then
ESS_FTP = "NO"
ESS_Tested = "YES"
Me.Fails_SF.Test.SetFocus
End If

The first two aren't working though. The MsgBox is displayed but it still moves onto next control.
Second two are working fine.
I know this code can be shortened but I've separated it out so I can see it easier and try to find what's wrong!
(Ignore title sorry another problem I have but may be solvable with this issue!)

Thanks in advance!
 
Last edited:

missinglinq

AWF VIP
Local time
Today, 18:09
Joined
Jun 20, 2003
Messages
6,423
The first two aren't working because you can't set Focus to a Control from that Control's AfterUpdate event...you have to use its BeforeUpdate event.

If it fails the validation test...you simply use

Cancel = True

and the Focus will automatically stay on that Control.

To be honest, validation the involves the values of multiple Controls generally has to be done in the Form_BeforeUpdate event.

Linq ;0)>
 

CJ_London

Super Moderator
Staff member
Local time
Today, 23:09
Joined
Feb 19, 2013
Messages
16,610
or turn the problem on its head - disable the controls that should not be completed until all the other required fields have been completed - then enable the control

something like

private sub checkalldone()
mylastcontrol.enabled=not (isnull(ctrl1) and isnull(ctrl2)…..)
end sub

and call from each of the relevant controls and the form oncurrent event
 

TobyMace

Registered User.
Local time
Today, 23:09
Joined
Apr 13, 2018
Messages
65
Hi Both! Thank you for your replies! I have managed to finally get it working with the use of Cancel = True.
I'll try your method CJ and see if it works just for fun! :)
Thanks again!
 

missinglinq

AWF VIP
Local time
Today, 18:09
Joined
Jun 20, 2003
Messages
6,423
Glad we could help!

Good luck with your project!

Linq ;0)>
 

Users who are viewing this thread

Top Bottom