Disabling the 'OK' button in a form

2305
2
08-12-2010 06:35 PM
SteveH
by
Occasional Contributor
I have a custom form of several pages where users are continually entering data on the first page only and then exiting.
Anyone know of a way of disabling the OK button until users reach the end of the form?

thanks
Steve
Tags (3)
0 Kudos
2 Replies
EricHajek1
Occasional Contributor
Hi Stephen, I don't know about disabling the OK button, but you can catch users hitting the OK button and dump them back to the form using something like this:


Sub OnFormCancel
Dim bResult
bResult = Application.MessageBox ("Are you sure you want to cancel?", apYesNo, "Cancel?")
 
If bResult = apNo Then
  ThisEvent.Result = False
End If
If bResult = apYes Then
  ThisEvent.Result = True
End If
End Sub


This was in the onquerycancel events of all of my pages so that if a user hits cancel, they get asked if they really mean it. You could do the same thing with the onOK event, asking if they really mean to hit OK. For a reason that escapes me right now I think you have to do it on each page, rather then on the form level.

Alternatively you could check variables on each of the pages using the onvalidate event, and by writing a Sub that checks the variables on each page, make sure that the user cannot exit until the required fields are entered and error checked, as seen below:


Sub ValidateUserPTwo
Dim objPg
Set objPg = ThisEvent.Object

If objPg.Controls("cboDP").value = "" Then
  ThisEvent.Result = False
  ThisEvent.MessageText = "You must select a Discharge Point Layer to Continue"
  ThisEvent.MessageType = apOKOnly + apExclamation
  Exit Sub
End If
             ThisEvent.Result = True
End Sub


So for instance, this forces the user to select a Discharge Point Layer. If the value of that combo box isn't empty, it falls through and hits ThisEvent.Result = True, allowing the page to be validated.
0 Kudos
SteveH
by
Occasional Contributor
Thanks Eric
that second script was just what I was looking for.:cool:
Cheers
Steve
0 Kudos