[AccessD] Updating Form Recordsource and Selecting Control

John Bodin jbodin at sbor.com
Thu Feb 9 21:31:07 CST 2017


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





--
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