Getting the focus on current textbox

M

Mark A. Sam

Hello,

The following code is on the ChangeEvent of a textbox. Line 4 makes a
hidden form, visible, but it also takes the focus off of the textbox being
type into. The textbox is in a subform called [LoadSheetsST]. I tried doing
Screen.PreviousControl.Setfocus from a listbox on the form being
displayed,[LoadSheetsPhoneViewer]. This set the focus to the subform
control, but not the textbox.

I also tried setting a variable, ctl (line 7) to the textbox and setting the
focus that way, but without success.

Thank you for any help


If IsNumeric(Me.ActiveControl.Text) Then
Dim ctl As Control
Set ctl = Me.ActiveControl
Forms![LoadSheetsPhoneViewer].Visible = True
Dim frm As Form
Set frm = Forms![LoadSheetsPhoneViewer]
ctl.SetFocus
frm![Company].RowSource = "SELECT Contacts.PHONE, Contacts.COMPANY,
Contacts.CITY, Contacts.STATE " & _
"FROM Contacts " & _
"GROUP BY Contacts.PHONE, Contacts.COMPANY,
Contacts.CITY, Contacts.STATE " & _
"HAVING Contacts.PHONE Is Not Null And Contacts.PHONE
Like '" & Me.ActiveControl.Text & "*' " & _
"ORDER BY Contacts.PHONE;"
Else
Forms![LoadSheetsPhoneViewer].Visible = False
End If
 
M

Mark A. Sam

I resolved this by setting the focus back to the Mainform
Forms![loadsheetsmain].SetFocus



If IsNumeric(Me.ActiveControl.Text) Then
If Not IsLoaded("LoadSheetsPhoneViewer") Then
DoCmd.OpenForm "LoadSheetsPhoneViewer", , , , , acHidden
End If
Forms![LoadSheetsPhoneViewer].Visible = True
Forms!loadsheetsmain!LoadSheetsST.Form!f1.SetFocus
Dim frm As Form
Set frm = Forms![LoadSheetsPhoneViewer]
frm.[txtValue] = "forms!" & Parent.Name & "!" & Me.Name & ".Form!" &
Me.ActiveControl.Name
frm![Company].RowSource = "SELECT Contacts.PHONE, Contacts.COMPANY,
Contacts.CITY, Contacts.STATE " & _
"FROM Contacts " & _
"GROUP BY Contacts.PHONE, Contacts.COMPANY,
Contacts.CITY, Contacts.STATE " & _
"HAVING Contacts.PHONE Is Not Null And Contacts.PHONE
Like '" & Me.ActiveControl.Text & "*' " & _
"ORDER BY Contacts.PHONE;"

Forms![loadsheetsmain].SetFocus


Else
Forms![LoadSheetsPhoneViewer].Visible = False
End If
 
M

Mark A. Sam

I thought I had it but this only works for the first textbox becuase it gets
the focus then the main form gets the focus. I can't put the focus on the
current textbox.
 
M

Mark A. Sam

Addressing the variable frm to make the form visible worked.

frm.Visible = True

rather than

Forms![loadsheetsmain].SetFocus
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top