From: hotplate on
Hi,

I need to save a record in a subform before trying to close the main
form.

I tried creating a save command in the subform and calling it when
trying to close the main form. Unfortunately I could not figure out
how to do this.

The reason I need to save subform record is because I am adding the
numbers in the subform to see if they equal a number in the main
record, if they don't match the form will not close. I can't even
check for a match if the subform record does not get saved before
closing.

I am using a command button to close the main form.

Thanks
From: Jeanette Cunningham on
Do both forms have a table or query as their record source?
Are you using the link master and link child fields?

If you are using bound forms, does your save button have code like this?
If Me.Dirty = True Then
Me.Dirty = False
End If


Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia

"hotplate" <hotplate74(a)gmail.com> wrote in message
news:eeb1bc9b-ca70-4f07-b3d9-ba612ad4155f(a)n35g2000yqm.googlegroups.com...
> Hi,
>
> I need to save a record in a subform before trying to close the main
> form.
>
> I tried creating a save command in the subform and calling it when
> trying to close the main form. Unfortunately I could not figure out
> how to do this.
>
> The reason I need to save subform record is because I am adding the
> numbers in the subform to see if they equal a number in the main
> record, if they don't match the form will not close. I can't even
> check for a match if the subform record does not get saved before
> closing.
>
> I am using a command button to close the main form.
>
> Thanks


From: hotplate on
Yes both forms have a table as their record source and they are
linked.

I am using the wizard provided save command, so no I don't have that
code.

I am not sure where this is going.

On Dec 8, 2:28 am, "Jeanette Cunningham"
<n...(a)discussions.microsoft.com> wrote:
> Do both forms have a table or query as their record source?
> Are you using the link master and link child fields?
>
> If you are using bound forms, does your save button have code like this?
> If Me.Dirty = True Then
>     Me.Dirty = False
> End If
>
> Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia
>
> "hotplate" <hotplat...(a)gmail.com> wrote in message
>
> news:eeb1bc9b-ca70-4f07-b3d9-ba612ad4155f(a)n35g2000yqm.googlegroups.com...
>
> > Hi,
>
> > I need to save a record in a subform before trying to close the main
> > form.



>
> > I tried creating a save command in the subform and calling it when
> > trying to close the main form.  Unfortunately I could not figure out
> > how to do this.
>
> > The reason I need to save subform record is because I am adding the
> > numbers in the subform to see if they equal a number in the main
> > record, if they don't match the form will not close.  I can't even
> > check for a match if the subform record does not get saved before
> > closing.
>
> > I am using a command button to close the main form.
>
> > Thanks

From: Jeanette Cunningham on
Thanks for providing the info.
When you are using bound forms and main form and subform are linked using
the link master and link child fields, access does save the subform record
when user clicks out of the subform onto the main form.

I sugest that you remove the save button from the subform - as access will
automatically save the subform data when user clicks something on the main
form.

Put an unbound textbox on the subform and set its control source to
=Sum([FieldName])

To check for a match when on the main form, you can use code like this-->
Private Function CheckForMatch() As Boolean
If Me.[NameOfControl] = Me.[SubformControlName].Form.[NameOf
TheUnboundTextBox] Then
CheckForMatch = True
Else
CheckForMatch = False
End If
End Function

Then on the unload event for the main form, you can go
If Not CheckForMatch = True Then
Cancel = True
End If

The above should prevent the main form closing unless the numbers match.


Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia


"hotplate" <hotplate74(a)gmail.com> wrote in message
news:7920904c-1f12-4e5c-b9dd-4651ec50bf2e(a)9g2000yqa.googlegroups.com...
Yes both forms have a table as their record source and they are
linked.

I am using the wizard provided save command, so no I don't have that
code.

I am not sure where this is going.

On Dec 8, 2:28 am, "Jeanette Cunningham"
<n...(a)discussions.microsoft.com> wrote:
> Do both forms have a table or query as their record source?
> Are you using the link master and link child fields?
>
> If you are using bound forms, does your save button have code like this?
> If Me.Dirty = True Then
> Me.Dirty = False
> End If
>
> Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia
>
> "hotplate" <hotplat...(a)gmail.com> wrote in message
>
> news:eeb1bc9b-ca70-4f07-b3d9-ba612ad4155f(a)n35g2000yqm.googlegroups.com...
>
> > Hi,
>
> > I need to save a record in a subform before trying to close the main
> > form.



>
> > I tried creating a save command in the subform and calling it when
> > trying to close the main form. Unfortunately I could not figure out
> > how to do this.
>
> > The reason I need to save subform record is because I am adding the
> > numbers in the subform to see if they equal a number in the main
> > record, if they don't match the form will not close. I can't even
> > check for a match if the subform record does not get saved before
> > closing.
>
> > I am using a command button to close the main form.
>
> > Thanks


From: hotplate on
I had code very similar to this checking for a match (your code is
better though).

My problem is that if they enter the number in the control of the
subform and try to close the form without first exiting that control,
the sum does not update before trying to close. This would only be a
problem if the control in the subform is the very last control the
user enters a value.



On Dec 8, 2:32 pm, "Jeanette Cunningham"
<n...(a)discussions.microsoft.com> wrote:
> Thanks for providing the info.
> When you are using bound forms and main form and subform are linked using
> the link master and link child fields, access does save the subform record
> when user clicks out of the subform onto the main form.
>
> I sugest that you remove the save button from the subform - as access will
> automatically save the subform data when user clicks something on the main
> form.
>
> Put an unbound textbox on the subform and set its control source to
> =Sum([FieldName])
>
> To check for a match when on the main form, you can use code like this-->
> Private Function CheckForMatch() As Boolean
> If Me.[NameOfControl] = Me.[SubformControlName].Form.[NameOf
> TheUnboundTextBox] Then
>     CheckForMatch = True
> Else
>     CheckForMatch = False
> End If
> End Function
>
> Then on the unload event for the main form, you can go
> If Not CheckForMatch = True Then
>     Cancel = True
> End If
>
> The above should prevent the main form closing unless the numbers match.
>
> Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia
>
> "hotplate" <hotplat...(a)gmail.com> wrote in message
>
> news:7920904c-1f12-4e5c-b9dd-4651ec50bf2e(a)9g2000yqa.googlegroups.com...
> Yes both forms have a table as their record source and they are
> linked.
>
> I am using the wizard provided save command, so no I don't have that
> code.
>
> I am not sure where this is going.
>
> On Dec 8, 2:28 am, "Jeanette Cunningham"
>
> <n...(a)discussions.microsoft.com> wrote:
> > Do both forms have a table or query as their record source?
> > Are you using the link master and link child fields?
>
> > If you are using bound forms, does your save button have code like this?
> > If Me.Dirty = True Then
> > Me.Dirty = False
> > End If
>
> > Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia
>
> > "hotplate" <hotplat...(a)gmail.com> wrote in message
>
> >news:eeb1bc9b-ca70-4f07-b3d9-ba612ad4155f(a)n35g2000yqm.googlegroups.com....
>
> > > Hi,
>
> > > I need to save a record in a subform before trying to close the main
> > > form.
>
> > > I tried creating a save command in the subform and calling it when
> > > trying to close the main form. Unfortunately I could not figure out
> > > how to do this.
>
> > > The reason I need to save subform record is because I am adding the
> > > numbers in the subform to see if they equal a number in the main
> > > record, if they don't match the form will not close. I can't even
> > > check for a match if the subform record does not get saved before
> > > closing.
>
> > > I am using a command button to close the main form.
>
> > > Thanks