SetFocus Is Not Working (1 Viewer)

JithuAccess

Member
Local time
Today, 11:48
Joined
Mar 3, 2020
Messages
267
Hello Guys,

This is my Code

Code:
Private Sub strPHN_LostFocus()

Dim db As Database
Dim rst As Recordset
Dim STRSQL As String

Set db = CurrentDb()

STRSQL = "Select [tblMaster Table].[strID], [tblMaster Table].[strName],[tblMaster Table].[strKeywords],[tblMaster Table].[datMeeting Date],[tblMaster Table].[strStatus of Application] from [tblMaster Table] where [tblMaster Table].[strPHN]=" & "'" & Me.strPHN & "';"

Set rst = db.OpenRecordset(STRSQL)

If rst.RecordCount = 0 Then
    MsgBox "This ID " & Me.strID & " Not Found in Master Table, Please check the ID", vbInformation
    Me.strID.SetFocus
    Exit Sub
End If

Me.strPHN = rst.Fields(1)
Me.strName = rst.Fields(2)
Me.strKeywords = rst.Fields(3)
Me.datMeeting_Date = rst.Fields(4)

Me.Recalc

End Sub

Here, I want to display the matching Records from the Main Table to my Form based on ID. It is working perfect. If I have entered an ID which is not in the Master Table, a Message Box is displaying BUT the Code Me.strID.SetFocus is not working. The Focus is going to the Next Text Box strName.

The Tab Index of strID is 0 and Tab Index of strName is 1 and Tab Stop properties of Both these Text boxes are True.

Could you please help me how to solve this?

Thanks
 

NauticalGent

CopyPaster of the First Order
Local time
Today, 13:48
Joined
Apr 27, 2015
Messages
3,914
I see...those were the only situations I could think of. When the form opens, are you able to edit the strID field?
 

JithuAccess

Member
Local time
Today, 11:48
Joined
Mar 3, 2020
Messages
267
You can't set the focus to a control that already has it.
So if strID receives the focus after strPHN it won't work.
I have put my Code in the Got Focus event of strName and it is working. Though I am not sure this is the correct way to solve this

Thank You
 

NauticalGent

CopyPaster of the First Order
Local time
Today, 13:48
Joined
Apr 27, 2015
Messages
3,914
Now I REALLY don't have a clue! Are you able to upload a copy of your DB? If not, hopefully someone else will have an idea
 

Users who are viewing this thread

Top Bottom