Form OnCurrent event not firing - bug workaround (1 Viewer)

mort

Registered User.
Local time
Today, 05:18
Joined
Mar 19, 2018
Messages
30
Hello all,

I have a problem with my forms OnCurrent event. It does not fire when I move to the first record. The problem lies with the AfterUpdate event for a listbox that is on the form.
This problem have been argued on several forums, but i have not found an answer on how to go around this bug.

Easy explanation:
FrmA contains a listbox and several bound controls. The bound controls are textboxes and checkboxes.

On frmA there is some code in the OnCurrent event of the form. The codes are mainly simple and short if statements:
If me.checkboxA = true then
Me.txtboxA.visible= true
else
Me.txtboxA.visible=false
end if

And so on.

To navigate the records on the form I use a listbox. In the AfterUpdate event I have the following code:
DoCmd.SearchForRecord , "", acFirst, "[ID] = " & Str(Nz(Screen.ActiveControl, 0))

The problem is that the forms OnCurrent events works fine when navigating all records in the listbox EXCEPT for the first record. For example if you go from record X to record 1, the OnCurrent event does NOT fire, but if you go from record X to record 2,3 or anyone else above the first, it works fine.

I need help rewriting the listbox AfterUpdate event so that the forms OnCurrent event fires when moving from record X to the first record.

I use Access 2010.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 12:18
Joined
May 7, 2009
Messages
19,247
You alsi use the Load event of the Form

Private Sub Form_Load()
Call Form_Current
End Sub

There is also another method where you setup the listbox to have an initial value on the form's load event:

Private sub form_load()
Me.list = me.list.itemdata(0)
Call list_afterupdate
End sub

You can specifically use your listbix name instead of screen.activecontrol.
 
Last edited:

JHB

Have been here a while
Local time
Today, 06:18
Joined
Jun 17, 2012
Messages
7,732
Why do you not have the code under the AfterUpdate event?
Code:
..
[I][I]DoCmd.SearchForRecord , "", acFirst, "[ID] = " & Str(Nz(Screen.ActiveControl, 0))
[/I]if me.checkboxA = true then [/I]
[I]Me.txtboxA.visible= true[/I]
[I]else[/I]
[I]Me.txtboxA.visible=false[/I]
[I]end if
..
[/I]
 

mort

Registered User.
Local time
Today, 05:18
Joined
Mar 19, 2018
Messages
30
Thanks JHB, putting the code in the AfterUpdate for the listbox worked. I feel stupid for not thinking of that myself.
 

JHB

Have been here a while
Local time
Today, 06:18
Joined
Jun 17, 2012
Messages
7,732
You're welcome, good luck. :)
 

Galaxiom

Super Moderator
Staff member
Local time
Today, 14:18
Joined
Jan 20, 2009
Messages
12,853
BTW Your code can be simplified to:
Code:
Me.textboxA.Visible = Me.checkboxA
 

static

Registered User.
Local time
Today, 05:18
Joined
Nov 2, 2015
Messages
823
I just tested this and it's true, this doesn't work
DoCmd.SearchForRecord , "", acFirst, "[ID] = " & Str(Nz(Screen.ActiveControl, 0))

But this does
Me.Recordset.FindFirst "[ID] = " & Str(Nz(Screen.ActiveControl, 0))
 

Mark_

Longboard on the internet
Local time
Yesterday, 21:18
Joined
Sep 12, 2017
Messages
2,111
@ Mort,

For myself, I make a sub that does all of these kinds of things, then call the sub from where needed. This way you have your code in one spot but reference from more than one spot. Makes it far easier to maintain. By habit these little pieces I make are called "TCO_" and a reference that I can remember, such as "TCO_UpdateControlsAfterLoad"
 

sunkerala

New member
Local time
Today, 09:48
Joined
Apr 26, 2020
Messages
11
I just tested this and it's true, this doesn't work
DoCmd.SearchForRecord , "", acFirst, "[ID] = " & Str(Nz(Screen.ActiveControl, 0))

But this does
Me.Recordset.FindFirst "[ID] = " & Str(Nz(Screen.ActiveControl, 0))
MARK THIS AS ANSWER
THANK YOU [B]static[/B] FOR YOUR PRECIOUS HELP
 

Users who are viewing this thread

Top Bottom