2 in 1 questions

A

an

Hello!

In form, based in table, I have unbound colored objects.
They are showed, or not showed, according data values.
To work fine I would like to solve two questions:

1 - When form open don't actualize the unbound objects accordinga data
values already saved in table. If I use mouse roler, actualize data. With
PgDown/Up key, actualize too;

2 - When new data is enter, directly in form, don't actrualize immediatly
the unbound objects. Next, using mouse roler or PgDown/Up key, actualize too.

I expect your wise help, please.
an
 
W

Wayne Morgan

For #1, the result would be that they don't show when you open the form and
it moves to the first record. The items would then show if you move to
another record, including moving back to the first record.

To do this, set a "flag" variable in the form's Open event. Check for this
in the Current event and skip displaying the items if the flag is set then
clear the flag. The flag variable will need to have form level scope, so it
will need to be Dim'ed in the Declarations section of the form's code
module, where it says "Option Compare Database".

Option Compare Database
Option Explicit
Dim bolFlag As Boolean

In the Open event:
bolFlag = True

In the Current event:
If Not bolFlag Then
If (Your Condition) Then
Me.ctlMyControl.Visible = True
'add another control here
Else
Me.ctlMyControl.Visible = False
End If
End If
bolFlag = False


For the second one, check to see if we're at a new record. If so, don't
display the items until we move to another record first.

For this, add the following to the Current event after the lines above.

If Me.NewRecord Then
Me.ctlMyControl.Visible = False
End If

Add as many controls as you need, one line at a time, inside the If
statements.
 
A

an

Thank you very much for your reply.

After aply your solution, about #1, in "Option Compare Database", in the
"Open Event" and "Current Event", don't work fine for me.
The situation is similar with the last. When we open the form, in 1st
record, the unbound objects don't show according with that value. Only
"sincronize" after PgDown/Up or roller mouse (?)

Thanks.
an
 
W

Wayne Morgan

You said that you don't want them to "actualize" when you first open the
form, but only AFTER you press page up/down or scroll the mouse. Is that
correct? The IF statement is deliberately preventing this because it sounded
as if that was what you wanted.
 
A

an

Sorry if I induced you in error.

I would like:

1 - Open the form already with unbound objects according with value, such as
it only happens later scroll de mouse or PgUp/Down. After this all right;
2 - When we change value in text box, it had effect, moving the state of
objects.

Isn't it possible?...

Many thanks.
an
 
W

Wayne Morgan

Yes, for that you would use the Current event of the form and the
AfterUpdate event of each of the controls that you enter the data in. The
Current event of the form will set the display when you move from record to
record, including the first record as the form opens. The AfterUpdate event
of the controls will run the code when you change the data in the control.
It will be the same code in all of the locations. If you wanted (depending
on how many of these you're doing, it may not be worth while for just a
couple of lines of code) you could create a separate sub in the form's
module then call it from each of the events above. Since you want it to
always work, the code would be the same as before, just without the flag
variable and the limiting If statements. You will still need one If
statement to turn the display on or off.

If (Your Condition) Then
Me.ctlMyControl.Visible = True
'add another control here
Else
Me.ctlMyControl.Visible = False
End If

Place this in the form's Current event (adjusting the names to match yours)
and the AfterUpdate event of each control that will cause a change to what
is visible.

The other option I mentioned would be to create a Sub in the form's module
with this code:

Private Sub SetVisible()
If (Your Condition) Then
Me.ctlMyControl.Visible = True
'add another control here
Else
Me.ctlMyControl.Visible = False
End If
End Sub

Then in each of the event procedures, you would simply use the line:

SetVisible

Use which ever method is less typing for you. The other advantage of the
separate sub, is that if you change it later you only have to change it in
one place.
 
A

an

Grrrr!

I think to do all right but when form open and numeric data is < Avg appear
always unbond object GreenON visible when it would have to be RedON.
When go to 2nd record and return to 1st already it is all good.
Initialy don't recognized the numeric value. Only after to past another and
return to 1st (?)

Thanks.
an
 
W

Wayne Morgan

If you're doing a Recalc in the Load event, what event did you put the code
in? If you put it in the Open event, it won't work, that is too soon and the
data isn't ready. By time you get to the Current event, it is ready. Also,
the Properties sheet for Events should show [Event Procedure] for On
Current, then click the ... button to the right of it to go to the Current
event in the code editor and enter the code.
 
A

an

Hello!
Ok, using the code in OnCurrent and AfterUpdate, it lacked Me.Recalc in
OnLoad.
Now work fine, for me.
Thank you very much.
an


Wayne Morgan said:
If you're doing a Recalc in the Load event, what event did you put the code
in? If you put it in the Open event, it won't work, that is too soon and the
data isn't ready. By time you get to the Current event, it is ready. Also,
the Properties sheet for Events should show [Event Procedure] for On
Current, then click the ... button to the right of it to go to the Current
event in the code editor and enter the code.

--
Wayne Morgan
MS Access MVP


an said:
WM,

Problem solved with Me.Recalc in On Load.
Thanks for all.
an
 

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