How to Update Main when Closing Pop

D

doyle60

I posed this question under a different subject and after seven emails
it wasn't solved to my needs and so I am posing it again.

How do I update or requery a main form when a pop up form is closed,
but leave the main on the same record. As we all well know,
requerying often leaves the form on the first record.

The data entered in the pop up will change certain fields on the
main. One of them is a command button that bolds its name if there is
underlying data behind it. It knows if there is underlying data
through an invisible sub and an invisible control calling that sub.

It's a nice little feature of mine of been doing lately. If you have
entered data on the pop you know it from the button being bold. If
you hit the button and it is not bold, it is ready for a new record
and data to be entered.

The pop also is synchronized with the main.

Thanks,

Matt
 
A

Albert D. Kallal

the following should work:

when you on the main form and the button is clicked to launch the popup
based on the SAME record, ensure that you written the current record to disk
(else it come back and tell you that someone else has modified the
record...that someone else is the other form!!).

So, we have:

if me.Dirty = True then
me.dirty = false ' write record to disk
end if

docmd.OpenForm "some other form",,,"id = " & me!id

The above opens a form to the same record. The user can edit that record...

You can make the above form dialog if your wish. To refresh the form we were
on to display/show updates, simply go:

me.Refresh

You can place the refresh code in the forms activate event if you don't want
to specific code this in the popup forms close event.....
 
D

doyle60

Thanks.

This seems a little harder than I wanted. Why is it that I just can't
write code on the on close event of the pop up that requeries the
main? When I thought to do this, I never imagined it would ever be so
involved.

Actually, I was going to put this code on a command button as well (on
the pop up) because some may not want to close the pop up but still
update the main.

I sort of just want a general code that updates this form without it
loosing the record it is on.

Perhaps I need a module for this? If so, what would be the code for
that?

I need this code in other ways too, that have nothing to do with pop
ups.

Is there an easier, more general approach?

Thanks,

Matt
 
D

doyle60

Thanks.

This seems a little harder than I wanted. Why is it that I just can't
write code on the on close event of the pop up that requeries the
main? When I thought to do this, I never imagined it would ever be so
involved.

Actually, I was going to put this code on a command button as well (on
the pop up) because some may not want to close the pop up but still
update the main.

I sort of just want a general code that updates this form without it
loosing the record it is on.

Perhaps I need a module for this? If so, what would be the code for
that?

I need this code in other ways too, that have nothing to do with pop
ups.

Is there an easier, more general approach?

Thanks,

Matt
 
A

Albert D. Kallal

Thanks.

This seems a little harder than I wanted. Why is it that I just can't
write code on the on close event of the pop up that requeries the
main? When I thought to do this, I never imagined it would ever be so
involved.

You mean my suggestion of ONE LINE of code is involved?

If one line of code is too much, then there not a lot I can do to help you
here...

My example suggestion means that you don't have to put ANY code in the close
event of the form that was just opened. Why would you want or desire to
write a whole whack of code for every form that the current form just
opened? The example I gave also works great because if you do things like
change the forms name, copy it to another application, there is no
"dependent" code needed to be placed in any other form. As I said, I don't
know why you think ONE LINE of code in the form activate event is "so
involved"

My solution allows your own form to launch 1, 2, or 10 different forms, and
when any of them returns back, a me.refreash is executed. This will update
any changes that have occurred to data on the "main" form in question.
I sort of just want a general code that updates this form without it
loosing the record it is on.

Yes, the one line of code I suggested in the forms activate event will do
the trick. The "only" caveat you have to worry about is to ensure you force
a disk write **if** the form you are launching has the ability to
edit/modify the record that the calling form was on.

So,

me.Refresh

Will do what you want. Refresh will display any changes made to the data
displayed by the current form...in fact, this works even in the case of
continues form.

Now, it is entirliary possible that your left out some MAJOR details here.
Such as the 2nd form being launched is not just possible editing the current
record, but is in fact adding new records?

Anyway, me.Refresh in the forms activate event will refresh and display any
changes that have occurred to the form's data. If you need the forms
reocrdset to display "new" added reocrds, but still remain on the current
record (that is diffent question on your part by the way), then in place of
me.fresh, you can place a public function in the forms code module that is:


Public function MyRequery

dim lngID as long


lngID = me!id
me.Requery
me.Recordset.FindFirst "id = " & me!id

end if


The above assumes a pk ID of id (which is the default).


So, in the current form (the activate event) you can now go:

me.MyRefresh


If you need a button, or for some strange un-known reason you can't use the
forms activeVate event, then you can go from another form:

forms!NameOfForm.Form.MyRefresh

Perhaps I need a module for this? If so, what would be the code for
that?

As mentioned, if you just looking to have a form update any changes made to
the current record it is on, then a me.Refresh will do the trick.

If you need the form to display additional records added, then use the
public function idea I listed above...
Is there an easier, more general approach?

Gee, more general then my original suggestion? I been in eh IT business for
about 20 years, and a one line code solution that will refresh when you
return from ay form...hum, I don't think that kind of solution can be
beat...
 
A

Albert D. Kallal

Thanks.

This seems a little harder than I wanted. Why is it that I just can't
write code on the on close event of the pop up that requeries the
main? When I thought to do this, I never imagined it would ever be so
involved.

You mean my suggestion of ONE LINE of code is involved?

If one line of code is too much, then there not a lot I can do to help you
here...

My example suggestion means that you don't have to put ANY code in the close
event of the form that was just opened. Why would you want or desire to
write a whole whack of code for every form that the current form just
opened? The example I gave also works great because if you do things like
change the forms name, copy it to another application, there is no
"dependent" code needed to be placed in any other form. As I said, I don't
know why you think ONE LINE of code in the form activate event is "so
involved"

My solution allows your own form to launch 1, 2, or 10 different forms, and
when any of them returns back, a me.refreash is executed. This will update
any changes that have occurred to data on the "main" form in question.
I sort of just want a general code that updates this form without it
loosing the record it is on.

Yes, the one line of code I suggested in the forms activate event will do
the trick. The "only" caveat you have to worry about is to ensure you force
a disk write **if** the form you are launching has the ability to
edit/modify the record that the calling form was on.

So,

me.Refresh

Will do what you want. Refresh will display any changes made to the data
displayed by the current form...in fact, this works even in the case of
continues form.

Now, it is entirliary possible that your left out some MAJOR details here.
Such as the 2nd form being launched is not just possible editing the current
record, but is in fact adding new records?

Anyway, me.Refresh in the forms activate event will refresh and display any
changes that have occurred to the form's data. If you need the forms
reocrdset to display "new" added reocrds, but still remain on the current
record (that is diffent question on your part by the way), then in place of
me.fresh, you can place a public function in the forms code module that is:


Public function MyRequery

dim lngID as long


lngID = me!id
me.Requery
me.Recordset.FindFirst "id = " & me!id

end if


The above assumes a pk ID of id (which is the default).


So, in the current form (the activate event) you can now go:

me.MyRefresh


If you need a button, or for some strange un-known reason you can't use the
forms activeVate event, then you can go from another form:

forms!NameOfForm.Form.MyRefresh

Perhaps I need a module for this? If so, what would be the code for
that?

As mentioned, if you just looking to have a form update any changes made to
the current record it is on, then a me.Refresh will do the trick.

If you need the form to display additional records added, then use the
public function idea I listed above...
Is there an easier, more general approach?

Gee, more general then my original suggestion? I been in eh IT business for
about 20 years, and a one line code solution that will refresh when you
return from ay form...hum, I don't think that kind of solution can be
beat...
 
D

doyle60

Thanks for your patience.

I put a command button on the main form with the code:

Me.Refresh

And I placed another on the pop with:

Forms.EntryForm2.Refresh '(a variation of the code I found in your
email).

Both of them only refresh the invisible sub and control that refers to
the invisible sub. But both of them do not bold the command button
that should have bold writing on it when there is data in the
invisible sub (the data that went into the pop).

To get the command button to bold when moving from record to record on
the main, I use this code (poorly editing from a text to text ID to a
number to number ID) and put it in the On Current event:

If DCount("*", "VTIPOListtbl", "VTIPO=""" & Me.PO & """") > 0 Then
Command5453.FontWeight = 700
Else
Command5453.FontWeight = 400
End If

So how do I get this code to run again on the pop so to bold the
command?

Sorry I thought your response difficult. If I could simply put:

Forms.EntryForm2.Refresh

on the on close event of the pop, then why not just mention that? I'm
not being sassy or rude, believe me. I don't understand what "dirty"
means nor "writing to disk" and thought you may not have understood
that my form was synched, and loose, that is, users are free to
navigate from record to record on the main when pop is open.

So the question is, if I follow your method I find difficult, will it
solve the command button being bold issue or not? I'm thinking it
won't.

Matt
 
D

doyle60

Thanks for your patience.

I put a command button on the main form with the code:

Me.Refresh

And I placed another on the pop with:

Forms.EntryForm2.Refresh '(a variation of the code I found in your
email).

Both of them only refresh the invisible sub and control that refers to
the invisible sub. But both of them do not bold the command button
that should have bold writing on it when there is data in the
invisible sub (the data that went into the pop).

To get the command button to bold when moving from record to record on
the main, I use this code (poorly editing from a text to text ID to a
number to number ID) and put it in the On Current event:

If DCount("*", "VTIPOListtbl", "VTIPO=""" & Me.PO & """") > 0 Then
Command5453.FontWeight = 700
Else
Command5453.FontWeight = 400
End If

So how do I get this code to run again on the pop so to bold the
command?

Sorry I thought your response difficult. If I could simply put:

Forms.EntryForm2.Refresh

on the on close event of the pop, then why not just mention that? I'm
not being sassy or rude, believe me. I don't understand what "dirty"
means nor "writing to disk" and thought you may not have understood
that my form was synched, and loose, that is, users are free to
navigate from record to record on the main when pop is open.

So the question is, if I follow your method I find difficult, will it
solve the command button being bold issue or not? I'm thinking it
won't.

Matt
 
A

Albert D. Kallal

Thanks for your patience.

I put a command button on the main form with the code:

Me.Refresh

All that button will do is simply refresh the
forms underlying data. That is what the purpose of me.Refresh is for.

It not cause any code to all of a sudden run in that form
(hence the code in the forms on-current will not run either).

It not clear if your popup form modifies the same record as this
main form or not?

If the popup form only modifies controls direct on main form, then
we don't need a refresh. And, if the popup form is adding records
to another table, then again, me.Refresh on the main form is NOT
needed and it will NOT help here.
And I placed another on the pop with:

Forms.EntryForm2.Refresh '(a variation of the code I found in your
email).

I don't think the above will even compile (and run without errors?
(Hint: when you enter any code, the next step is to go debug->compile
before you attempt to run the code).

The syntax needs to be:

forms!EnteryForm2.Refresh

or, in our case we going to use

forms!EnteryForm2.MyRefresh <-- "myRefresh" is going to be our custom
code here.

"refresh" is a built in command, but read onward, we going to build our bold
code to run with MyRefresh.
Both of them only refresh the invisible sub and control that refers to
the invisible sub. But both of them do not bold thethe command button

Right...as mentioned refreshing the data is not going to cause some code in
the form to all of a sudden run. It is just not clear how the popup form
modifies the main forms data.
To get the command button to bold when moving from record to record on
the main, I use this code (poorly editing from a text to text ID to a
number to number ID) and put it in the On Current event:

If DCount("*", "VTIPOListtbl", "VTIPO=""" & Me.PO & """") > 0 Then
Command5453.FontWeight = 700
Else
Command5453.FontWeight = 400
End If

So how do I get this code to run again on the pop so to bold the
command?

Ok, if the popup form modifies the same record with bold controls **on** the
popup form, then we need to:

1) force a refresh of the main forms data (we will use me.Refresh to do
this)

2) run your code to set the bold...

So, we may have to do both of the above.

It not clear now if the popup form is editing the same record data
here. (or does it place values direct into controls on the main form),
or is it simply adding records to another related table?

Lets assume code that will work for either case, and then you can
simply remove the additional code if popup modifies controls direct
on the main form.

So, I would still build a public function called myRefresh in the main form.

The code would look like:

Public Function MyRefresh

me.Refresh
me.MyBold

End Function

I would also add a public function to the main form called:

Public Function MyBold

If DCount("*", "VTIPOListtbl", "VTIPO=""" & Me.PO & """") > 0 Then
Command5453.FontWeight = 700
Else
Command5453.FontWeight = 400
End If

end Function

We could also I guess remove the above code from the form's on-current and
replace it with


me.MyBold

(the above would just mean we only have one copy of the bold code here).

Sorry I thought your response difficult. If I could simply put:

Forms.EntryForm2.Refresh

on the on close event of the pop, then why not just mention that?

Well, actually, I did..

However, you asked for "general" code, not just a "one" off coding solution.
Now perhaps you miss-used the term "general" here, but a "general" solution
is a solution one that gives you more flexibility (is not a one-off.

On the other hand, I did in fact mention that you COULD put the code in the
forms close event, but I simply then went on to point out that there is no
need to do this if you are closing that popup form.

On the other hand, the problem here the popup is not being closed
after data entry??? So, it makes zero sense to use the popup forms
close event when we not closing the form.
(it was not clear to me that the popup form stays open).

If the popup form is adding related records (not the same table),
then use the popup forms after update event and place the
following in the popup forms after update event:

forms!MainForm.MyRefresh

Hence, if the popup form is not editing the same table, then you not need to
execute a me.Refresh in the main forms code (you could remove the me.Refresh
in the myRefresh routine).

I don't understand what "dirty"
means nor "writing to disk" and thought you may not have understood
that my form was synched, and loose, that is, users are free to
navigate from record to record on the main when pop is open.

Ok, I explain this concept. If the popup form modifies the values of
controls direct on the main form, then the dirty issue is a NON issue. And,
if the popup form is adding records to a different table, then again this
means you can remove the me.Refresh in all of our code examples. We don't
need it.

However, if the popup form modifies the ***SAME*** record direct (as on the
main form), then we have to tell the main form that the record been changed
(by changed, we mean dirty in access Terminology ). So, the command
me.refresh is the command that tells the form that the underlying data been
changed by another forms code. If two forms edit the same record, each form
will not see the change until a me.Refresh occurs. that is why the dirty
concept is so important here.

Hence, if the popup form does NOT have a data source set and simply modifies
controls direct on the main form (those invisible controls), then you don't
need the me.refresh. And, if the popup form is adding records to a related
table and again NOT modifying the record of the main form then again we ONLY
need to run the mybold code. The refresh part is not needed. So, you ONLY
need the refresh code if the main forms record becomes dirty (dirty = the
concept that the record been modified *and* has a data pending to be written
to disk). When you change a value on a form, the record is dirty, but if you
pull the plug, you notice that the record will not have been yet saved (it
not written from the computer memory to the hard drive. This is the same as
pulling the plug while editing a word document, if the document has not been
saved...you loose your changes. We could for the sake of this discussion
state that the word document is "dirty" after editing.

Now that you mentioned that the popup form remains open, then using the
close event of the popup makes absolute NO sense here because then we not
closing the form are we?

So, the code to "run" our custom refresh code in the main form has to be
placed in the event (or events) in the popup form that causes the main form
to change (or become dirty). The likely two possible cases are the popup
forms after update event (if adding related records), or simply behind the
button or controls in the popup form that causes the change in the main
form.

I think a forms!MainForm.MyRefresh in the popup forms after update event
should do the trick here if that popup form is adding related records to
another table.
 
A

Albert D. Kallal

Thanks for your patience.

I put a command button on the main form with the code:

Me.Refresh

All that button will do is simply refresh the
forms underlying data. That is what the purpose of me.Refresh is for.

It not cause any code to all of a sudden run in that form
(hence the code in the forms on-current will not run either).

It not clear if your popup form modifies the same record as this
main form or not?

If the popup form only modifies controls direct on main form, then
we don't need a refresh. And, if the popup form is adding records
to another table, then again, me.Refresh on the main form is NOT
needed and it will NOT help here.
And I placed another on the pop with:

Forms.EntryForm2.Refresh '(a variation of the code I found in your
email).

I don't think the above will even compile (and run without errors?
(Hint: when you enter any code, the next step is to go debug->compile
before you attempt to run the code).

The syntax needs to be:

forms!EnteryForm2.Refresh

or, in our case we going to use

forms!EnteryForm2.MyRefresh <-- "myRefresh" is going to be our custom
code here.

"refresh" is a built in command, but read onward, we going to build our bold
code to run with MyRefresh.
Both of them only refresh the invisible sub and control that refers to
the invisible sub. But both of them do not bold thethe command button

Right...as mentioned refreshing the data is not going to cause some code in
the form to all of a sudden run. It is just not clear how the popup form
modifies the main forms data.
To get the command button to bold when moving from record to record on
the main, I use this code (poorly editing from a text to text ID to a
number to number ID) and put it in the On Current event:

If DCount("*", "VTIPOListtbl", "VTIPO=""" & Me.PO & """") > 0 Then
Command5453.FontWeight = 700
Else
Command5453.FontWeight = 400
End If

So how do I get this code to run again on the pop so to bold the
command?

Ok, if the popup form modifies the same record with bold controls **on** the
popup form, then we need to:

1) force a refresh of the main forms data (we will use me.Refresh to do
this)

2) run your code to set the bold...

So, we may have to do both of the above.

It not clear now if the popup form is editing the same record data
here. (or does it place values direct into controls on the main form),
or is it simply adding records to another related table?

Lets assume code that will work for either case, and then you can
simply remove the additional code if popup modifies controls direct
on the main form.

So, I would still build a public function called myRefresh in the main form.

The code would look like:

Public Function MyRefresh

me.Refresh
me.MyBold

End Function

I would also add a public function to the main form called:

Public Function MyBold

If DCount("*", "VTIPOListtbl", "VTIPO=""" & Me.PO & """") > 0 Then
Command5453.FontWeight = 700
Else
Command5453.FontWeight = 400
End If

end Function

We could also I guess remove the above code from the form's on-current and
replace it with


me.MyBold

(the above would just mean we only have one copy of the bold code here).

Sorry I thought your response difficult. If I could simply put:

Forms.EntryForm2.Refresh

on the on close event of the pop, then why not just mention that?

Well, actually, I did..

However, you asked for "general" code, not just a "one" off coding solution.
Now perhaps you miss-used the term "general" here, but a "general" solution
is a solution one that gives you more flexibility (is not a one-off.

On the other hand, I did in fact mention that you COULD put the code in the
forms close event, but I simply then went on to point out that there is no
need to do this if you are closing that popup form.

On the other hand, the problem here the popup is not being closed
after data entry??? So, it makes zero sense to use the popup forms
close event when we not closing the form.
(it was not clear to me that the popup form stays open).

If the popup form is adding related records (not the same table),
then use the popup forms after update event and place the
following in the popup forms after update event:

forms!MainForm.MyRefresh

Hence, if the popup form is not editing the same table, then you not need to
execute a me.Refresh in the main forms code (you could remove the me.Refresh
in the myRefresh routine).

I don't understand what "dirty"
means nor "writing to disk" and thought you may not have understood
that my form was synched, and loose, that is, users are free to
navigate from record to record on the main when pop is open.

Ok, I explain this concept. If the popup form modifies the values of
controls direct on the main form, then the dirty issue is a NON issue. And,
if the popup form is adding records to a different table, then again this
means you can remove the me.Refresh in all of our code examples. We don't
need it.

However, if the popup form modifies the ***SAME*** record direct (as on the
main form), then we have to tell the main form that the record been changed
(by changed, we mean dirty in access Terminology ). So, the command
me.refresh is the command that tells the form that the underlying data been
changed by another forms code. If two forms edit the same record, each form
will not see the change until a me.Refresh occurs. that is why the dirty
concept is so important here.

Hence, if the popup form does NOT have a data source set and simply modifies
controls direct on the main form (those invisible controls), then you don't
need the me.refresh. And, if the popup form is adding records to a related
table and again NOT modifying the record of the main form then again we ONLY
need to run the mybold code. The refresh part is not needed. So, you ONLY
need the refresh code if the main forms record becomes dirty (dirty = the
concept that the record been modified *and* has a data pending to be written
to disk). When you change a value on a form, the record is dirty, but if you
pull the plug, you notice that the record will not have been yet saved (it
not written from the computer memory to the hard drive. This is the same as
pulling the plug while editing a word document, if the document has not been
saved...you loose your changes. We could for the sake of this discussion
state that the word document is "dirty" after editing.

Now that you mentioned that the popup form remains open, then using the
close event of the popup makes absolute NO sense here because then we not
closing the form are we?

So, the code to "run" our custom refresh code in the main form has to be
placed in the event (or events) in the popup form that causes the main form
to change (or become dirty). The likely two possible cases are the popup
forms after update event (if adding related records), or simply behind the
button or controls in the popup form that causes the change in the main
form.

I think a forms!MainForm.MyRefresh in the popup forms after update event
should do the trick here if that popup form is adding related records to
another table.
 
D

doyle60

Thanks. I will get to this later today.

Let me explain the situation. The main form is for ordering product
(panties, sleepwear, robes, etc.). It is an over-complicated and
packed form. I was asked to also keep track of certain government
tests that need to be done before shipping. This testing got a bit
hairy recently because of the China lead scare some months ago.

But the tests that need to be done for each PO can actually be grouped
for a range of POs. We may order product on three POs and all three
should be grouped together for several tests. So I built a Testtbl,
TestPOtbl, and TestNeededtbl, and some others.

So it all works just fine. The only problem is when someone closes
the pop up and they have added the current PO to a test, that dumb
command button doesn't bold.

Now the refresh code does update the hidden sub on the main and the
control calling that hidden sub, the two things needed to synch the
pop and bold the command.

It's really a minor issue but something I wanted to solve.

So this should answer your question about what data is being updated:
Only a sub on the main and a control calling that sub. And the
refresh is updating that but not the command.

Matt
 
D

doyle60

Thanks. I will get to this later today.

Let me explain the situation. The main form is for ordering product
(panties, sleepwear, robes, etc.). It is an over-complicated and
packed form. I was asked to also keep track of certain government
tests that need to be done before shipping. This testing got a bit
hairy recently because of the China lead scare some months ago.

But the tests that need to be done for each PO can actually be grouped
for a range of POs. We may order product on three POs and all three
should be grouped together for several tests. So I built a Testtbl,
TestPOtbl, and TestNeededtbl, and some others.

So it all works just fine. The only problem is when someone closes
the pop up and they have added the current PO to a test, that dumb
command button doesn't bold.

Now the refresh code does update the hidden sub on the main and the
control calling that hidden sub, the two things needed to synch the
pop and bold the command.

It's really a minor issue but something I wanted to solve.

So this should answer your question about what data is being updated:
Only a sub on the main and a control calling that sub. And the
refresh is updating that but not the command.

Matt
 
D

doyle60

Thanks Albert,
But I ran out of time and had to begin something new. I will have to
get to all this later. I saved your response. If you don't hear from
me again, thanks so much for your patience.

Matt
 
D

doyle60

Thanks Albert,
But I ran out of time and had to begin something new. I will have to
get to all this later. I saved your response. If you don't hear from
me again, thanks so much for your patience.

Matt
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top