> I'm trying to determine if the Visit subform (subformVisits) has a new[color=blue]
> record or been changed, i.e. dirty. The form that contains the subform is
> named Clients.[/color]
If the focus has been moved from the subform to the main form or to another
subform, the subform's record will be saved (no longer "dirty"). If the focus is
currently on that subform, you need only check its dirty property:
If Me.Dirty Then
'Current record has been added or edited
Else
'No edits or no current record
End If
[color=blue]
> I have this code in the Add Client btn:
> If Forms!Clients.subformVisits!VisitDirty = True Then
> MsgBox "Visit subform is dirty!"
> Else
> MsgBox "problems. subform not dirty"
> End If
> But it displays err "application defined or object defined error."[/color]
You syntax is incorrect. You must reference the subform *control's* "Form"
property:
Forms!MainFormName.SubformControlName.Form!Control Name
This assumes that "SubformControlName" is the name of the subform *control* on
the main form, not the name of the subform (although both may share the same
name).
[color=blue]
> The field VisitDirty is an unbound & not visible field with a True/False
> format in the details section of subformVisits. Its code is:
>
> Private Sub VisitDirty_AfterUpdate()
> ' to see if the subform is "dirty", i.e. has changed or new record
> If Me.Dirty Then
> Me.VisitDirty = True
> End If
>
> End Sub[/color]
Why would you be trying to set the value of the control after it has been
edited? That's the only time this code would run. Again, you can simply check
the form's "Dirty" property directly ("If Me.Dirty Then ...").
[color=blue]
> The reason for the unbound VisitDirty field is that I was having a devil of
> a time trying to check if the subform was dirty. Probably didn't have the
> syntax correct but tried setting a form var below but also had errs. Even
> tried going to the control level but no success.
>
> SET frmClient = Forms!Clients.subformVISITs[/color]
Again, you must reference the subform *control's* "Form" property.
[color=blue]
> All the above is as the result of a test that caused an err...
>
> The user enters a new record in the Visit subfrom and has tabbed thru the
> fields to the DateEntered field into which the current system date is
> entered if a new record.
>
> At this point, the DateEntered field is highlighted. If the user - me - then
> clicks on the Add Client button instead of the Save button which could/will
> happen, I want to save the record in the subform, then move away from the
> Dateentered field of the subform to the first name field before calling for
> a new record in the Client form using DoCmd.GoToRecord , , acNewRec
>
> If the cursor is in the DateEntered field when the new record is created
> then the current date is entered to the field but an err will soon display
> because there is no new client number (autonumber) to insert into the Visit
> table clientnum field.[/color]
Isn't the "Add Client" command button on the main (Client) form? If so, the
focus will no longer be in the subform, so I guess I don't see where you are
going here unless you are trying to add a child record (in the subform) before
you have created a client record (in the main form).
[color=blue]
> Guess I need to better understand the Access event model among other things.
> Using Access97 and both the client and subformVisit forms are bound to the
> Clients and Visits table, respectively.
>
> BTW, what is the difference between using the bang (!) and the dot (.) when
> referencing a form as in
> Forms!Clients!subformVisits and Forms!Clients.subformVisit.[/color]
From a practical viewpoint, not much, but neither will work unless you are
referencing the subform *control's* "Form" property (I know - nag, nag, nag
<g>).
:-)
--
Bruce M. Thompson
bthmpson@mvps.org (See the Access FAQ at
http://www.mvps.org/access)[color=blue][color=green]
>> NO Email Please. Keep all communications[/color][/color]
within the newsgroups so that all might benefit.<<