[AccessD] Updating Form Recordsource and Selecting Control

David Emerson newsgrps at dalyn.co.nz
Thu Feb 9 22:37:14 CST 2017


Hi John,

Yes, that is what I am doing except I had 

DoCmd.GoToControl "txtWallpaperBarcode"

Instead of 

Me!txtWallpaperBarcode.SetFocus

I tried your suggestion but with the same result.

If I click in the txtWallpaperBarcode control and press enter then the
cursor comes back to the same control but if I change the data (activating
the AfterUpdate event) then the control doesn't return.

I also discovered that if I don't update the Recordsource then the cursor
returns to the first control as desired.  It all seems to be connected with
the new recordset.

Regards

David Emerson
Dalyn Software Ltd
Wellington, New Zealand



-----Original Message-----
From: AccessD [mailto:accessd-bounces at databaseadvisors.com] On Behalf Of
John Bodin
Sent: Friday, 10 February 2017 4:31 p.m.
To: Access Developers discussion and problem solving
Subject: Re: [AccessD] Updating Form Recordsource and Selecting Control

Hi David,

If I put two controls on a form - Text0 and Text2 - and in the On Enter
event of Text2 I put me.Text0.Setfocus, I can't move my cursor into Text2.
It automatically jumps back to Text0.  So in my dummy table (recordset) I
have a field called ID and if I type in "2" into Text0, the below Select
Statement fires correctly, and cursor moves right back to Text0 for next ID
to be input.  No problem with Recordset changing.  Is this similar to what
you are trying to do?
 
Private Sub Text0_AfterUpdate()
    Me.RecordSource = "Select * From [Aging Sample] Where ID = " & Me.Text0
End Sub

Private Sub Text2_Enter()
    Me.Text0.SetFocus
End Sub


John

-----Original Message-----
From: AccessD [mailto:accessd-bounces at databaseadvisors.com] On Behalf Of
David Emerson
Sent: Thursday, February 09, 2017 6:47 PM
To: 'Access Developers discussion and problem solving'
Subject: [AccessD] Updating Form Recordsource and Selecting Control

Hi Listers,

I have a form with an unbound control called txtWallpaperBarcode.  When text
is entered into the control and the after update event triggered then the
form's recordset is updated using the entered text as a filter as follows:

        Set rstTemp = basRunDataObject("dbo.spfrmWallpaperLookup '" &
Me!txtWallpaperBarcode & "'", adCmdText)
        If rstTemp.RecordCount <> 0 Then
            Set Me.Recordset = rstTemp
       End If

This all works fine.  Once the recordset is updated I would like the control
to get the focus again.  This is the part I am struggling with.

The control is the first in the tab order.  Next in tab order is an unbound
control (txtAfterBarcode) which has the following code in the Enter event:

DoCmd.GoToControl "txtWallpaperBarcode"

When the Update code is finished the second control doesn't get the focus.
I assume this is because the forms recordset is updated.  I have tried
forcing the move at the end of the Update code with this line:

    DoCmd.GoToControl "txtAfterBarcode"

But I get an error saying that I can't move the focus to the control
txtAfterBarcode.  It seems to be due to the Enter event wanting to move it
out again.

Any suggestions?

Regards

David Emerson
Dalyn Software Ltd
Wellington, New Zealand




More information about the AccessD mailing list