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.
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?"
'Add supplier form open here
Else
txtSupplierShortName = ""
End If
Else
txtSupplierFullName = DLookup("[Name]", "tblSupplier", "[ShortName]='" & Forms!frmPurchaseInvoice!txtSupplierShortName & "'"
txtSupplierID = DLookup("[SupplierID]", "tblSupplier", "[ShortName]='" & Forms!frmPurchaseInvoice!txtSupplierShortName & "'"
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.