What event, or what code? (1 Viewer)

fat controller

Slightly round the bend..
Local time
Today, 21:34
Joined
Apr 14, 2011
Messages
758
I have a form that has an on current event where it checks the value of a few check boxes, and depending on the result it sets a label to visible or not - works just fine.

However, I have a second form that opens from this main form and when a user changes anything on this second form, it has a bearing on the aforementioned check boxes, which I would then like to have the relevant effect on the main form.

I have tried using the same code that I have in the on current event, in the on got focus event, but that doesn't work. I have tried getting the close event on the second form to refresh the main form (.refresh) - that doesn't work. Re-querying the main form sends it back to the first record (as expected), so that is no good either; the only way I can currently get it to work is to close and re-open the main form.

Is there a more elegant solution?
 

maw230

somewhat competent
Local time
Today, 15:34
Joined
Dec 9, 2009
Messages
522
I have a form that has an on current event where it checks the value of a few check boxes, and depending on the result it sets a label to visible or not - works just fine.

However, I have a second form that opens from this main form and when a user changes anything on this second form, it has a bearing on the aforementioned check boxes, which I would then like to have the relevant effect on the main form.

I have tried using the same code that I have in the on current event, in the on got focus event, but that doesn't work. I have tried getting the close event on the second form to refresh the main form (.refresh) - that doesn't work. Re-querying the main form sends it back to the first record (as expected), so that is no good either; the only way I can currently get it to work is to close and re-open the main form.

Is there a more elegant solution?

So, if a change is made on the second form, the main form checkboxes update, but that update doesn't trigger the on current code to display the label? Or the checkboxes don't update?
 

MarkK

bit cruncher
Local time
Today, 13:34
Joined
Mar 17, 2004
Messages
8,187
What you need is a public method on FormA that can be called from FormA's current event handler, but also that other consumers can call if they feel like it, so consider this arrangement on FormA . . .
Code:
Private Sub Form_Current()
   Me.ResetForm
End Sub

Public Sub ResetForm()
[COLOR="Green"]'  public method that updates visual presentation of the form[/COLOR]
   Me.lbSomeLabel.Visible = [I]<someCondition>[/I]
   Me.lbSomeOtherLabel.Visible = [I]<someOtherCondition>[/I]
End Sub
Now, let's say you have a FormB that alters the outcome of FormA's <someCondition> or <someOtherCondition>, and you want FormA (if it is open) to reset its presentation.
Code:
Private Sub FormBValue_AfterUpdate()
[COLOR="Green"]'  calls FormA.ResetForm[/COLOR]
   Const FN as string = "FormA"
   If CurrentProject.AllForms(FN).IsLoaded Then Forms(FN).ResetForm
End Sub
 

fat controller

Slightly round the bend..
Local time
Today, 21:34
Joined
Apr 14, 2011
Messages
758
I've just had a further play with it - sometimes it updates the checkboxes on the main form (record is saved by the code for the close command on the second form), whereas other times they do not; I have just had a write conflict message twice (that is a new one, not seen before), so I am now stumped.

The main form has an open event that selects a new record, and that needs to remain, so closing and re-opening could be a pain in the bum?
 

fat controller

Slightly round the bend..
Local time
Today, 21:34
Joined
Apr 14, 2011
Messages
758
What you need is a public method on FormA that can be called from FormA's current event handler, but also that other consumers can call if they feel like it, so consider this arrangement on FormA . . .
Code:
Private Sub Form_Current()
   Me.ResetForm
End Sub

Public Sub ResetForm()
[COLOR=Green]'  public method that updates visual presentation of the form[/COLOR]
   Me.lbSomeLabel.Visible = [I]<someCondition>[/I]
   Me.lbSomeOtherLabel.Visible = [I]<someOtherCondition>[/I]
End Sub
Now, let's say you have a FormB that alters the outcome of FormA's <someCondition> or <someOtherCondition>, and you want FormA (if it is open) to reset its presentation.
Code:
Private Sub FormBValue_AfterUpdate()
[COLOR=Green]'  calls FormA.ResetForm[/COLOR]
   Const FN as string = "FormA"
   If CurrentProject.AllForms(FN).IsLoaded Then Forms(FN).ResetForm
End Sub

This, coupled with a save record command on each of the fields on the second form has proved to be perfect :)

Thank you :)
 

Users who are viewing this thread

Top Bottom