[AccessD] Sub Form Current Event

Dan Waters dwaters at usinternet.com
Sun Jun 13 13:10:37 CDT 2004


Jim and Gustav,

This gives me something to work with!

Thanks!
Dan

-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Gustav Brock
Sent: Sunday, June 13, 2004 12:38 PM
To: Access Developers discussion and problem solving
Subject: Re: [AccessD] Sub Form Current Event

Hi Jim and Dan

You can also use a Static in OnCurrent:

  Static varCurrentID As Variant
  Dim varID As Variant

  varID = Me!ID
  If IsNull(varID) Then
    ' This is a new record.
    ' Run OnCurrent code for a new record.
    ... ' Your code here.
  ElseIf varID = varCurrentID Then
    ' The current record has not moved.
  Else
    ' The current record has moved, or OnCurrent
    ' runs for the first time: varCurrentID is Null.
    ' Run OnCurrent code once.
    ... ' Your code here.
    ' Store ID of the current record.
    varCurrentID = varID
  End If

Or, if nothing special is going to happen for a new record:

  varID = Me!ID
  If varID = varCurrentID Then
    ' The current record has not moved.
  Else
    ' The current record has moved, or
    ' this is a new record, or OnCurrent
    ' runs for the first time: varCurrentID is Null.
    ' Run OnCurrent code once.
    ... ' Your code here.
    ' Store ID of the current record.
    varCurrentID = varID
  End If

/gustav


>  OnCurrent fires quite a bit as you'll discover for a whole lot of
different
> reasons.  For example, it will fire several times during a delete process
as
> well.  If you have some code in there that you only want to have happen at
> specific times and only execute once, you need to protect it with a flag
> variable:

> In declarations section:

>   Dim fDoOnCurrentOnce as integer

> and in the OnCurrent

>   If fDoOnCurrentOnce = True then
>     ' Do your processing here
>     fDoOnCurrentOnce = False
>   End If


>   and then in various places, when you want processing to occur:

>    fDoOnCurrentOnce = True

> Jim Dettman
> President,
> Online Computer Services of WNY, Inc.
> (315) 699-3443
> jimdettman at earthlink.net

> -----Original Message-----
> From: accessd-bounces at databaseadvisors.com
> [mailto:accessd-bounces at databaseadvisors.com]On Behalf Of Dan Waters
> Sent: Sunday, June 13, 2004 12:30 PM
> To: 'Database Advisors'
> Subject: [AccessD] Sub Form Current Event

> Hello to everyone on a nice Sunday morning!  (at least in Minnesota)

> When I move to a different record on a main form, the Current event on a
> subform will run twice in succession before the Current event runs in the
> main form.

> Does anyone know how to cause the subform current event to run only once
in
> this circumstance?

> Thanks!

> Dan Waters

-- 
_______________________________________________
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com




More information about the AccessD mailing list