The main form contains general information related to each record (the
one).
The subform contains information at a lower level (the many).
The main form must contain items such as routing number, title, and source
to be considered a record. If any of these are Null, I want the user to
enter a value before they are allowed to save the data to the database and
close the form.
The subform must contain items related to the "steps" taken such as action
plan and estimated completion date. If these are Null, I want the user to
enter a value before they are allowed to save the data to the database and
close the subform.
My thought was to have the entire form/subform validated, when the user
clicks a button (Save & Close). Right now only the parent is validated.
I tried adding validation and referencing the subform within the parent,
but
I get a messaging saying it can't find the form (subform).
If (Eval("[Forms]![frmOther Weakness Corrective Actions (New
Entry)]![Deficiency Source] = 'SCAMPI' and [Forms]![frmOther Weakness
Corrective Actions (New Entry)]![ProcessAreas] is Null")) Then
MsgBox "A Value for 'Process Area' is Required.", vbOKOnly, "Required
Value Missing"
intIsError = 1
End If
If (Eval("[Forms]![frmOther Weakness Corrective Actions (New Entry)]![OCD]
is Null")) Then
MsgBox "A Value for the weakness ' Estimated Completion Date' is
Required.", vbOKOnly, "Required Value Missing"
intIsError = 1
End If
If (Eval("[Forms]![frmOther Weakness Corrective Actions (New
Entry)]![Status] is Null")) Then
MsgBox "A Value for 'Status' is Required.", vbOKOnly, "Required Value
Missing"
intIsError = 1
End If
If (Eval("[Forms]![Other Corrective Action Plan
subform1]![CorrectiveActionPlanItem] is Not Null and [Forms]![Other
Corrective Action Plan subform1]![OCD] is Null")) Then
MsgBox "A Value for 'Corrective Action Plan Estimated Completion
Date.",
vbOKOnly, "Required Value Missing"
intIsError = 1
End If
Jeff Boyce said:
As I mentioned, standard Access main form/subform construction requires a
record in the main form before a subform record can be entered. I still
don't have enough information to tell if your main form/subform is
standard.
One advantage to using the standard approach is that you can validate the
main form's record (i.e., the "one" side of a one-to-many relationship)
before attempting to add a subform record (the "many" side). Of course,
this assumes that your data is well-normalized and organized in a pair of
tables related one-to-many. Is this a fair assumption?
(still) More information, please...
Regards
Jeff Boyce
Microsoft Office/Access MVP
There is data in both the form and subform which must be validated
before
a
record is considered complete enough to be entered into the database.
I had this as two separate input forms, but the client didn't like that
approach.
:
If you are using a standard main form/subform construction, there is
NO
activity in the form that is your subform UNTIL it gets the focus.
Why
would you be clicking a button in the main form when its data entered
in
the
subform that needs validation?
More info, please...
Regards
Jeff Boyce
Microsoft Office/Access MVP
If the validation is taking place when a user clicks a button on the
parent
form, how would putting the code on the subform be executed?
:
If you are saying that you'd like Access to check on the record you
are
entering in a subform, have you tried putting your validation code
in
that
subform (*actually, you'd put it in the form you are using as a
subform*)?
Regards
Jeff Boyce
Microsoft Office/Access MVP
I have created a form and wish to validate entries within the form
and a
subform.
I have placed the form validation code as part of the "Close"
button.
Example:
If (Eval("[Forms]![frmOther Weakness Corrective Actions (New
Entry)]![OCD]
is Null")) Then
MsgBox "A Value for 'Estimated Completion Date' is Required.",
vbOKOnly,
"Required Value Missing"
intIsError = 1
End If
I now wish to validate entries on the subform. I tried calling
the
"[subForm]", but get an error saying basically the method does
not
exist.
How can I validate the subform entries?
Also, I wish to spell check the form and subform. I can spell
check
the
form, but the subform is ignored.
Dim ctlSpell As Control
Dim frm As Form
Set frm = Screen.ActiveForm
DoCmd.SetWarnings False
For Each ctlSpell In frm.Controls
If TypeOf ctlSpell Is TextBox Then
If Len(ctlSpell) > 0 Then
With ctlSpell
'only spell check the text boxes with a value
of
true
in
their tag property.
If .Tag = "True" Then
.SetFocus
.SelStart = 0
.SelLength = Len(ctlSpell)
DoCmd.RunCommand acCmdSpelling
End If
End With
End If
End If
Next
MsgBox "Spell check complete.", vbInformation + vbOKOnly,
"Finished."
DoCmd.SetWarnings True
DoCmd.Close
End If