View Single Post
 
Old 05-11-2011, 02:52 AM
Cbrehm Cbrehm is offline Windows 7 64bit Office 2003
Novice
 
Join Date: May 2011
Posts: 8
Cbrehm is on a distinguished road
Default .setfocus not working why?

Code:
Private Sub addcophone_Enter()
If IsError(Application.Match(addcozip, Range("zipcode").Columns(1), 0)) Then
    addcozip.SetFocus 'does not work
End If
End Sub
In userforms.textfields why can I not setfocus from a textbox but can from a command button?

In the following setfocus is not available at all.


Code:
Sub addzip(ByVal zipfield As MSForms.TextBox, ByVal cityfield As MSForms.TextBox, ByVal statefield As MSForms.TextBox)
    'carl brehm 05-08-2011
    'zip is zipcode entered in field afterupdate
    'zipfield is thee name of textbox for the zip code
    'cityfield is the name of the textbox for the city
    'statefield is the name of the textbox for the state
' zip code
Dim zip As Double
 If zipfield = Empty Then Exit Sub
 
zip = zipfield.Value 'get zipcode entered

    If IsError(Application.Match(zip, Range("zipcode").Columns(1), 0)) Then
        zipfield.Value = Empty 'value not found make user reenter
        cityfield.Value = Empty
        statefield.Value = Empty
        MsgBox ("That was not a valid Zip Code")
        'STATEFIELD.SETFOCUS NOT AVAIABLE HERE
        Exit Sub
    Else
        'lookup city and state to prefill textbox
        cityfield.Value = Application.WorksheetFunction.VLookup(zip, Range("zipcode"), 2, False)
        statefield.Value = Application.WorksheetFunction.VLookup(zip, Range("zipcode"), 3, False)
    End If

End Sub
Reply With Quote