Jeanette, Thanks for the post!
If possible, I would like to know if you could answer a small issue I',
having with a solution posted by Dirk Goldgar? (See his post/code below)
- I'm using your code suggestion to just check my Tab Control page 02
(very
helpful!)
- When the user clicks on cmdNext, it checks for Tab Control page02, and
then
calls Dirk's code
- Which performs the Validation on all "Required" fields, until all have
been
entered
Here's my current cmdNext button
-----------------------------------------------
Private Sub cmdNext_Click()
If Me.TabCtl0 = 1 Then
'page 02
Cancel = fncRequiredFieldsMissing(Me)
End If
'Me.TabCtl0 = Me.TabCtl0 + 1
'Me.cmdNext.Enabled = True
End Sub
-----------------------------------------------
Here is my question, and the place that I'm hung:
- Where do I move my old cmdNext code (see commented lines above) to allow
the User to get to the next page?
- I think I need to move it to Dirk's code, so that if all the Required
fields are completed, then the user is taken to the next Tab Control
page?
- But if I change the code in the Module, then it will only work for that
page only, and cannot be "called" if needed for other pages on my Tab
Control.
?
Hope this makes sense,
Thanks,
cw
Dirk Goldgar's code:
-------------------------------
Here's a function you can paste into a standard module and call from the
form's BeforeUpdate event. It checks every text box, combo box, list
box, and check box on the form, but only if the control's Tag property
is set to "Required". That lets you designate, by tagging, those fields
that are required. The function is passed a reference to the form to be
checked and returns True if required fields are missing, as well as
displaying a message and setting the focus to the first control that is
required but empty.
'----- start of function code -----
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, acCheckBox
If .Tag = "Required" 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
strErrorMessage = strErrorMessage & vbCr & _
" " & .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
MsgBox "The following fields are required:" & vbCr & _
strErrorMessage, _
vbInformation, "Required Fields Are Missing"
frm.Controls(strErrCtlName).SetFocus
fncRequiredFieldsMissing = True
Else
fncRequiredFieldsMissing = False
End If
End Function
'----- end of function code -----
To use the function, create a BeforeUpdate event for your form like
this:
'----- start of event procedure code -----
Private Sub Form_BeforeUpdate(Cancel As Integer)
Cancel = fncRequiredFieldsMissing(Me)
End Sub
'----- end of event procedure code -----
Jeanette said:
Hi cw,
your form can know if tab control page 01 is open by using the value of
the
tab control.
sample code-->
If Me.NameOfTabControl = 0 Then
'first page
Assuming there is not a subform on page 01 of tab control -
If the user has this page open, you can run a check on only those
particular
required fields on the main form's before update event.
If you are wanting to know when the user has entries in those 5 fields
without using before update, perhaps you could set up some code on the
after
update event for each or those particular controls.
Untested air code-->
If Not IsNull(Me.ControlName) Then
If Len(Me.NextCtlName1 & vbNullString) >0 Then
If Len(Me.NextCtlName2 & vbNullString) >0 Then
If Me.chk1 = True and Me.chk2 = True Then
Me.cmdNext.Visible = True
Else
Me.cmdNext.Visible = False
End If
'add the appropriate number of end ifs as needed.
Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia
I have searched the forums, but cannot get an answer to my question. Most
of
[quoted text clipped - 16 lines]