Setting tab order on form locks ability to edit records on the form (1 Viewer)

sleibo

New member
Local time
Today, 10:39
Joined
Dec 16, 2018
Messages
2
I have a form based upon a query.

1638248091012.png


Field next to Search Employee is named Search_Lname and is unbound, with On Lost Focus property calling:

Private Sub Search_Lname_LostFocus()
If Search_LName <> "" Then
Query = "SELECT * FROM Employees WHERE (([Employees].[LName])=[Forms].[ChangeEmployeeData].[Search_Lname])"
Me.RecordSource = Query
Me.Refresh
Else
On Error GoTo TestMacro_Err
DoCmd.GoToRecord , "", acNewRec

TestMacro_Exit:
Exit Sub

TestMacro_Err:
MsgBox Error$
Resume TestMacro_Exit

MsgBox ("You have entered a blank")
End If

End Sub
------------------------------------------------------------------
The "Current Employees" and "Released Employees" buttons call Reports. The search function works well (finally... took a while!).
I would like the cursor to appear in the Search_Lname field when opening the form. To do this I change the tab order. However whenever I change the tab order, I can no longer edit any record in the form (in Form View), and I can no longer scroll between different records that satisfy the search criteria (i.e. 3 people with same last names). Basically, when I change the tab order the form locks. If I change the tab order back to Auto Order, it all works fine again.
Please advise if anyone has seen this behavior, and how I might fix it. Thanks in advance!
 

June7

AWF VIP
Local time
Today, 06:39
Joined
Mar 9, 2014
Messages
3,883
Never encountered this. However, I would use AfterUpdate instead of LostFocus.

If you want to provide db for analysis, follow instructions at bottom of my post.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 23:39
Joined
May 7, 2009
Messages
15,037
you can Setfocus on Search_Lname textbox on the Load event of the Form:

Private Sub Form_Load()
Me![Search_Lname].Setfocus
End Sub
 

theDBguy

I’m here to help
Staff member
Local time
Today, 07:39
Joined
Oct 29, 2018
Messages
17,601
Hi. When you said you can no longer edit or scroll through the form, was it because it keeps going to a new record page?
 

oleronesoftwares

Registered User.
Local time
Today, 07:39
Joined
Sep 22, 2014
Messages
697
The following are two ways to go about it.

1. For each field in the order you want it, go to vba code
after update event of the preceeding field write the code
nextfield.setfocus

2. On form load event
set focus to the first field
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 10:39
Joined
May 21, 2018
Messages
5,908
It is highly unlikely that lname will ever equal "". It is pretty hard to force an empty string into a field without code.
You should be checking for null and if you want "" too.
if not (Search_LName & "") = "" Then

My guess is that as it loads it loses focus and the code fires. But since it is null and not "" the code continues.
This then returns a query with no records and thus uneditable
Query = "SELECT * FROM Employees WHERE [Employees].[LName])= NULL"
 

Users who are viewing this thread

Top Bottom