Yes, it is a subform, but it's name is "sfrmTaskAudit". "Comments" is a
control on the subform, and frmControls is a group of toggle buttons which
control navigation between the forms. I have since changed the code to use
Case statements instead. What I am trying to do is to prevent the user from
navigating away from the subform if they have not filled in required
information on the subform once a check box is selected. Here is the entire
code for the sub in more readable format:
Private Sub frmControls_Click()
Select Case frmControls
Case 1 ' goto correspondence details tab
If (Forms.sfrmTaskAudit.chkOther = -1) And ((IsNull(Forms.
sfrmTaskAudit.Comments)) Or (Forms.sfrmTaskAudit.Comments = "")) Then
DoCmd.Beep
'Comment required on Changes Details tab
MsgBox "Comment Required! Please Enter A Comment.", vbExclamation,
"Other Change Entered"
Forms.sfrmTaskAudit.chkEPDB.SetFocus
Forms.sfrmTaskAudit.Comments.SetFocus
'Force comment in comment field if Other is selected
frmControls.Value = 3
Else
DoCmd.GoToPage 1 'allow navigation away
End If
Case 2 'goto Routing details tab
If (CurrentRecord > Recordset.RecordCount) And (IsNull(Forms.
frmCorrespondence.ID)) Then 'adding new record
MsgBox "Must Enter Correspondence Information First!", vbExclamation,
"Required Information" 'force entry on first page
frmControls.Value = 1
DoCmd.GoToPage 1
Forms.frmCorrespondence.ID.SetFocus
'Go back to Correspondence info page
ElseIf Forms.sfrmTaskAudit.chkOther = -1 And ((IsNull(Forms.sfrmTaskAudit.
Comments)) Or (Forms.sfrmTaskAudit.Comments = "")) Then
DoCmd.Beep
' Comment required
MsgBox "Comment Required! Please Enter A Comment.", vbExclamation,
"Other Change Entered"
Forms.sfrmTaskAudit.chkEPDB.SetFocus
Forms.sfrmTaskAudit.Comments.SetFocus
' Force comment in comment field if Other is selected
frmControls.Value = 3
Else
DoCmd.GoToPage 2 'allow navigation to Page 2
End If
Case 3 'Goto Changes Details form
If (CurrentRecord > Recordset.RecordCount) And (IsNull(Forms.
frmCorrespondence.ID)) Then 'adding new record
MsgBox "Must Enter Correspondence Information First!", vbExclamation,
"Required Information" 'force entry on first page
frmControls.Value = 1
Forms.frmCorrespondence.ID.SetFocus
'DoCmd.GoToPage 1 'Go back to Correspondence info page
Else
DoCmd.GoToPage 4
End If
Case 4 'Goto Provider Details form
If (Forms.sfrmTaskAudit.chkOther = -1) And ((IsNull(Forms.sfrmTaskAudit.
Comments)) Or (Forms.sfrmTaskAudit.Comments = "")) Then
DoCmd.Beep
' Comment Required
MsgBox "Comment Required! Please Enter A Comment.", vbExclamation,
"Other Change Entered"
Forms.sfrmTaskAudit.chkEPDB.SetFocus
Forms.sfrmTaskAudit.Comments.SetFocus
' Force comment in comment field if Other is selected
frmControls.Value = 3
Else
DoCmd.GoToPage 3 'Allow navigation to provider info page
End If
End Select
End Sub
It doesn't like this:
If (Forms.sfrmTaskAudit.chkOther = -1) And ((IsNull(Forms.sfrmTaskAudit.
Comments)) Or (Forms.sfrmTaskAudit.Comments = ""))
Is "Forms.sfrmTaskAudit.chkOther" not the correct way to reference a control
on a subform? Maybe you're saying I need the name of the form the subform
lives on in there too?
I tried: ElseIf Forms.frmCorrespondence.sfrmTaskAudit.chkOther = -1 And (
(IsNull(Forms.frmCorrespondence.sfrmTaskAudit.Comments)) Or (Forms.
frmCorrespondence.sfrmTaskAudit.Comments = "")) Then
And it bombs too (frmCorrespondence is the main form, sfrmTaskAudit the
subform, chkOther the check box on the sub form). Seems to not like the
ElseIf?
I guess my question should be how to reference a control on a subform...
apparently I'm not doing it right.
Thanks!
>Is 'sfrmTaskAudit' a subform? If so, you need to add a layer to the reference:
>
[quoted text clipped - 6 lines]
>>
>> -Pamela
Pamela - 03 Aug 2005 12:41 GMT
Thanks for steering me in the right direction. :) I found this:
Referencing forms can be a bit tricky. The following statement shows the
general syntax that you should be using:
=[forms]![MyMainForm]![MySubForm].Form!MyControlNameOnSubForm
Please note that the important part is the period . between [MySubForm] and
Form
Now I just need to clean up my logic. :-P
-Pamela
>Yes, it is a subform, but it's name is "sfrmTaskAudit". "Comments" is a
>control on the subform, and frmControls is a group of toggle buttons which
[quoted text clipped - 103 lines]
>>>
>>> -Pamela