Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SetFocus not setting focus? 1

Status
Not open for further replies.

Egglar

Technical User
Apr 4, 2002
88
GB
Hi, I have a piece of code, ive tried in the after update/lost focus event of a txt box, and ive made it into a function and called it in the update/lost focus event of the txt box, however, the setfocus property just isn’t working at all.

Dim strCriteria As String
'search tblsupplier.shortname for enterd data, if not, show error message
strCriteria = txtSupplierShortName.Text
Dim intCount As Integer
If txtSupplierShortName = "" Then
MsgBox ("Please enter a supplier short name")
txtSupplierShortName.setfocus
Else
intCount = DCount("[Shortname]", "tblSupplier", "[Shortname] = '" & strCriteria & "'")
If intCount = 0 Then
If vbYes = MsgBox("That supplier does not exist. Would you like to add it now?", vbInformation + vbYesNo, "Add Supplier?") Then
'Add supplier form open here
Else
txtSupplierShortName = ""
End If
Else
txtSupplierFullName = DLookup("[Name]", "tblSupplier", "[ShortName]='" & Forms!frmPurchaseInvoice!txtSupplierShortName & "'") 'fill the full name text box from shortname
txtSupplierID = DLookup("[SupplierID]", "tblSupplier", "[ShortName]='" & Forms!frmPurchaseInvoice!txtSupplierShortName & "'") 'enter supplier id
End If
End If

Basically the code above determines whether the txt box is blank, if so displays a msg and puts focus back. If the txt box does contain text it searches the table to try and match the shortname, if it can’t find the shortname in the table it says so, offers the user to add a supplier, or gives them the option of saying no, in which case it clears the txt box and sets focus.

Problem im getting is its just not setting focus at all at either of them two points.

Any help greatly appreciated.

Elliot.
 
Don't ask me the logic of this one, but you need to set focus to another object first and then back to the one you want.
eg
Code:
MyTxtBox.SetFocus
txtSupplierShortName.setfocus

Sharon
 
Thanks for that, it was a simple fix much to my amazement!

How silly is that!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top