Validation subform

tihmir

Registered User.
Local time
Yesterday, 23:54
Joined
May 1, 2018
Messages
257
Hi all,
I have function name mdValidateData to validate data in my subform which is
on Navigation Control - Page Index 0
On Main form I have the following codes:

Code:
Private Sub Form_Load()
  'Add controls in order
  ctls.Add Me![fm_PSD]![cboInspection]
End Sub
Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)

    If Not DataValid2(Me, ctls) Then
        Cancel = True
    End If
End Sub
I have closeButton (on Main form) with code:
Code:
Private Sub closeButton_Click()
    
    Dim rtn As Long
    
    If DataValid2(Me, ctls) Then
        DoCmd.Close acForm, Me.Name
    Else
        rtn = MsgBox(" Select OK to Close without saving, or CANCEL to complete form.", vbOKCancel, "Validate Data")
    If rtn = vbOK Then
        DoCmd.Close acForm, Me.Name
    End If
  End If
End Sub
I have Navigation form with 5 pages. The first page (with Index 0) where is my subform fm_PSD. I need to prevent clicking on other pages if cboInspection on fm_PSD (subform on PageIndex 0) is Null
What I need to do?
 
First, it is considered of questionable value to add controls to a live form. You could get a proliferation of controls if not extremely careful. USUALLY what you do is predefine the control and then disable/hide it until you are ready for its use.

If you have pages and want to prevent them from responding, the OnClick event of that page selection control is probably the best place to go. The other possibility is that to select a choice from a combo (e.g. cboInspection) there is an on-click routine available for THAT type of control, too. The combination of events is that on Form's .OnLoad event, you would disable the controls you don't want to be selected, then in the cboInspection control's .OnClick event, you would have code to enable the things you wish to allow based on the selection.
 

Users who are viewing this thread

Back
Top Bottom