Form OnCurrent event not firing - bug workaround

mort

Registered User.
Local time
Today, 16:00
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.
 
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:
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]
 
Thanks JHB, putting the code in the AfterUpdate for the listbox worked. I feel stupid for not thinking of that myself.
 
You're welcome, good luck. :)
 
BTW Your code can be simplified to:
Code:
Me.textboxA.Visible = Me.checkboxA
 
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))
 
@ 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"
 
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

Back
Top Bottom