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.