Which Event

R

Robert T

Hello:

I'm fairly new to access 2003 and I wrote a simple little script that works,
but it only works partially. I wrote a basic checkbook application and I want
to disable certain fields. For example, if Trans_Type = "Debit", I want to
disable the Credits currency field. And if Trans_Type = "Credit", I want to
enable the Credits field and disable the Debits currency field.

I wrote the following script in the form's OnActivate Event. It works on the
first record, which is a "Debit", disabling the Credits currency field.
However, when I move onto a field which has a credit, such as a deposit, the
Debit Field remains enabled while the "Credits" field remains disabled.

'If the field Trans_Type is a Debit, Disable the Credits Field
'If the field Trans_Type is a Credit, Disable the Debits Field
Private Sub Form_Activate()
If (Me.TRANS_TYPE) = "Debit" Then
Me.DEBITS.Enabled = True
Me.CREDITS.Enabled = False
Else
Me.CREDITS.Enabled = True
Me.DEBITS.Enabled = False
End If
End Sub
 
R

Rob Parker

Assuming that when you say "However, when I move onto a field which has a
credit, ...", you actually mean "when I move to a record whose Trans_Type
field is 'Credit'", then just put your code in the form's Current event. It
will run there whenever the current record changes - including when the form
is opened.

HTH,

Rob
 
R

Robert T

Hello:

That worked. I haven't had an opportunity to add new records, but I assume
it will work properly then also.

OK, please explain the difference between the OnActivate and OnCurrent
events. I clicked on help but couldn't find an explanation of the two events
and when I should use them.

Thanks so much,
RT
 
R

Rob Parker

OnActivate occurs when the form is opened, or when it gains focus if you
have more than one window open within Access, and are moving between them.
[Note: a form also has a GotFocus event, and I don't really appreciate the
difference between these two - comment by an MVP might assist here, if any
one is watching this thread]. OnCurrent, as I said in my first reply,
occurs whenever you move between records within the form (including when the
first record loads after the form is opened). The Help file (for Access
2002 - it may vary for other versions, and may have nothing for Access 2000)
gives some information if you look under Events; in particular, it describes
which events occur in which order.

OnActivate events are rarely used, and most commonly (in my experience -
others may disagree) are used to control windows appearance - eg. switching
between maximised and normal views for particular forms/reports.

HTH,

Rob
 
M

Marshall Barton

Nice explanation of Activate vs Current, Rob.

Another important distinction between any GotFocus event and
the Activate event is that GotFocus does not fire when
switching between windows as the Acticate event does.

I have never had a use for the form's GotFocus event. IIRC,
it's a default event that's only triggered when the form has
no controls that can accept the focus. E.g. the form only
has labels and lines/rectangles.
--
Marsh
MVP [MS Access]


Rob said:
OnActivate occurs when the form is opened, or when it gains focus if you
have more than one window open within Access, and are moving between them.
[Note: a form also has a GotFocus event, and I don't really appreciate the
difference between these two - comment by an MVP might assist here, if any
one is watching this thread]. OnCurrent, as I said in my first reply,
occurs whenever you move between records within the form (including when the
first record loads after the form is opened). The Help file (for Access
2002 - it may vary for other versions, and may have nothing for Access 2000)
gives some information if you look under Events; in particular, it describes
which events occur in which order.

OnActivate events are rarely used, and most commonly (in my experience -
others may disagree) are used to control windows appearance - eg. switching
between maximised and normal views for particular forms/reports.


"Robert T" wrote
That worked. I haven't had an opportunity to add new records, but I assume
it will work properly then also.

OK, please explain the difference between the OnActivate and OnCurrent
events. I clicked on help but couldn't find an explanation of the two
events
and when I should use them.

Thanks so much,
RT
 
R

Rob Parker

Thanks for the extra info on the form's GotFocus event, Marsh. I'll file
that away for future forgetting ;-)

Rob

Marshall Barton said:
Nice explanation of Activate vs Current, Rob.

Another important distinction between any GotFocus event and
the Activate event is that GotFocus does not fire when
switching between windows as the Acticate event does.

I have never had a use for the form's GotFocus event. IIRC,
it's a default event that's only triggered when the form has
no controls that can accept the focus. E.g. the form only
has labels and lines/rectangles.
--
Marsh
MVP [MS Access]


Rob said:
OnActivate occurs when the form is opened, or when it gains focus if you
have more than one window open within Access, and are moving between them.
[Note: a form also has a GotFocus event, and I don't really appreciate the
difference between these two - comment by an MVP might assist here, if any
one is watching this thread]. OnCurrent, as I said in my first reply,
occurs whenever you move between records within the form (including when
the
first record loads after the form is opened). The Help file (for Access
2002 - it may vary for other versions, and may have nothing for Access
2000)
gives some information if you look under Events; in particular, it
describes
which events occur in which order.

OnActivate events are rarely used, and most commonly (in my experience -
others may disagree) are used to control windows appearance - eg.
switching
between maximised and normal views for particular forms/reports.


"Robert T" wrote
That worked. I haven't had an opportunity to add new records, but I
assume
it will work properly then also.

OK, please explain the difference between the OnActivate and OnCurrent
events. I clicked on help but couldn't find an explanation of the two
events
and when I should use them.

Thanks so much,
RT


:

Assuming that when you say "However, when I move onto a field which has
a
credit, ...", you actually mean "when I move to a record whose
Trans_Type
field is 'Credit'", then just put your code in the form's Current
event.
It
will run there whenever the current record changes - including when the
form
is opened.

HTH,

Rob

Hello:

I'm fairly new to access 2003 and I wrote a simple little script that
works,
but it only works partially. I wrote a basic checkbook application
and
I
want
to disable certain fields. For example, if Trans_Type = "Debit", I
want
to
disable the Credits currency field. And if Trans_Type = "Credit", I
want
to
enable the Credits field and disable the Debits currency field.

I wrote the following script in the form's OnActivate Event. It works
on
the
first record, which is a "Debit", disabling the Credits currency
field.
However, when I move onto a field which has a credit, such as a
deposit,
the
Debit Field remains enabled while the "Credits" field remains
disabled.

'If the field Trans_Type is a Debit, Disable the Credits Field
'If the field Trans_Type is a Credit, Disable the Debits Field
Private Sub Form_Activate()
If (Me.TRANS_TYPE) = "Debit" Then
Me.DEBITS.Enabled = True
Me.CREDITS.Enabled = False
Else
Me.CREDITS.Enabled = True
Me.DEBITS.Enabled = False
End If
End Sub
 
K

Ken Snell \(MVP\)

Marshall Barton said:
I have never had a use for the form's GotFocus event. IIRC,
it's a default event that's only triggered when the form has
no controls that can accept the focus. E.g. the form only
has labels and lines/rectangles.

and/or disabled controls that cannot accept a focus.
 

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