Hi All, I am trying to figure a way to validate data before it is sent in a report form. I currently can validate the main form easily using the following Code that I got from Dirk Goldgar: <Code Snippet Begin> Function fncRequiredFieldsMissing(frm As Form) As Boolean
Dim ctl As Access.Control Dim strErrCtlName As String Dim strErrorMessage As String Dim lngErrCtlTabIndex As Long Dim blnNoValue As Boolean
lngErrCtlTabIndex = 99999999 'more than max #controls
For Each ctl In frm.Controls With ctl Select Case .ControlType Case acTextBox, acComboBox, acListBox, acOptionGroup If .Tag = "Validate" And .Visible And .Enabled Then blnNoValue = False If IsNull(.Value) Then blnNoValue = True Else If .ControlType = acTextBox Then If Len(.Value) = 0 Then blnNoValue = True End If End If End If If blnNoValue Then .BackColor = vbRed strErrorMessage = strErrorMessage & vbCrLf & _ " " & .Name If .TabIndex < lngErrCtlTabIndex Then strErrCtlName = .Name lngErrCtlTabIndex = .TabIndex End If End If End If Case Else ' Ignore this control End Select End With Next ctl
If Len(strErrorMessage) > 0 Then Call MessageBox("The following fields are required:" & vbCrLf & _ strErrorMessage & "|False|&OK|False|Required Fields Are Missing") 'frm.Controls(strErrCtlName).SetFocus fncRequiredFieldsMissing = True Else fncRequiredFieldsMissing = False End If
End Function <Code Snippet End>
When I try to validate the subform using this, I get errors. I have tried referencing the subform, but naturally Access doesn't recognize it as being open.
The error I get is that the object can't be found.
Any help would be appreciated.
-- James B Gaylord For the Wolf comes the strength of the Pack, For the Pack comes the strength of the Wolf, -R. Kipling Office 2003 on Win XP SP2
Message posted via http://www.accessmonster.com
|
|