+ Reply to Thread
Results 1 to 20 of 20

on error loop

Hybrid View

  1. #1
    Registered User
    Join Date
    12-05-2008
    Location
    Ottawa
    Posts
    82

    on error loop

    Hi all,

    I have a search button that do a vlookup based on what option button is choosen. for a couple of weeks I have been trying to write a error handle but with no success. I want to write a few different handles but it doesn't work. here is my code. First handler I want to create is if not found please update the outlook list If not found again maybe a typo if not found choose another option than loop. I hope i explained this correctly..

    Private Sub cmdsearch_Click()
    Dim a As String
    Dim b As String
    Dim c As String
    Dim answer As String
    Dim answer2 As String
    
    
              
    
    'Continue:
    'On Error GoTo trap
    'On Error GoTo trap2
    'If obtclient.Value = False And optalias.Value = False Then
     ' MsgBox "Select an option to search for client", vbOKCancel'
    
    If obtclient.Value = True Then
    a = Application.WorksheetFunction.VLookup(Worksheets("INPUT").Range("B1"), Worksheets("Outlook Info").Range("a1:C10000"), 2, False)
    txtCname = txtsearch
    txtAlais = a
    txtphone = Application.WorksheetFunction.VLookup(Worksheets("INPUT").Range("B1"), Worksheets("Outlook Info").Range("a1:c10000"), 3, False)
    ElseIf optalias.Value = True Then
    b = Application.WorksheetFunction.VLookup(Worksheets("INPUT").Range("B1"), Worksheets("Outlook Info").Range("D1:F10000"), 3, False)
    txtAlais.Value = txtsearch
    txtCname = b
    txtphone = Application.WorksheetFunction.VLookup(Worksheets("INPUT").Range("B1"), Worksheets("Outlook Info").Range("D1:F10000"), 2, False)
    
    Else
    optphone.Value = True
    c = Application.WorksheetFunction.VLookup(Worksheets("INPUT").Range("B1"), Worksheets("Outlook Info").Range("g1:I10000"), 2, False)
    
     
    txtphone = txtsearch
    txtCname = c
    txtAlais = Application.WorksheetFunction.VLookup(Worksheets("INPUT").Range("B1"), Worksheets("Outlook Info").Range("g1:I10000"), 3, False)
    
    End If
    
    
    
    
     lblstartup.Visible = False
     lblstartup2.Visible = False
     
     lbldate.Visible = True
    txtdate.Visible = True
    'Frame3.Visible = False
    Frame2.Visible = True
    Frame5.Visible = True
    lblissue.Visible = True
    txtissue.Visible = True
    cmdsi.Visible = True
    lbltitle.Visible = True
    txttitle.Visible = True
    lblsystem.Visible = True
    txtsystem.Visible = True
    lblcomponent.Visible = True
    txtcomp.Visible = True
    lblitem.Visible = True
    txtitem.Visible = True
    Label4.Visible = True
    txtassign.Visible = True
    lbldescription.Visible = True
    txtdescription.Visible = True
    Label5.Visible = True
    txtsolution.Visible = True
     
     ' Resume Continue
      
    
    
    'answer = MsgBox("yes", vbQuestion + vbOKCancel, "Error")
    'If answer = vbOK Then Resume Continue
    
    'trap2:
    'answer2 = MsgBox("no", vbQuestion + vbOKCancel, "Error")
    'If answer2 = vbOK Then Resume Continue
    
    
    'MsgBox "Select an option to search for client", vbOKCancel
    
    
    
    
    
    
    End Sub
    Last edited by manforeyes; 01-12-2009 at 12:44 PM.

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    Why don't you use the VBA .Find method?
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Registered User
    Join Date
    12-05-2008
    Location
    Ottawa
    Posts
    82
    how can you help ?

  4. #4
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    I'm not sure what you are doing.

  5. #5
    Registered User
    Join Date
    12-05-2008
    Location
    Ottawa
    Posts
    82
    o.k I inport info from my work info so I can lookup easier and put it on a certain worksheet now based on that work sheet it will perform a vlookup based on what I select

  6. #6
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    Checking for errors with .Find is much easier, something like this

    Dim cl     As Range
        If obtclient.Value = True Then
    
            Set cl = Worksheets("Outlook Info").Range("b1:b10000").Find(Worksheets("INPUT").Range("B1").Value, LookIn:=xlValues)
            If cl Is Nothing Then
                MsgBox "Not there"
                'do something else
            Else: a = cl.Value
                txtCname = txtsearch
                txtAlais = a
            End If
            'etc

  7. #7
    Registered User
    Join Date
    12-05-2008
    Location
    Ottawa
    Posts
    82
    I have three criteria what do you mean do something else

  8. #8
    Registered User
    Join Date
    12-05-2008
    Location
    Ottawa
    Posts
    82
    what is LookIn:=xlValues)

  9. #9
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    take a look at the VBA helpfiles for .Find

    Do something else means exactly that, add code for whatver you want to do if the search is unsuccessful

  10. #10
    Registered User
    Join Date
    12-05-2008
    Location
    Ottawa
    Posts
    82
    cool like if nothing found go to 2 right ?

  11. #11
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    Somethin like that

  12. #12
    Registered User
    Join Date
    12-05-2008
    Location
    Ottawa
    Posts
    82
    Hi again I tried the find however doesn't seem to work this is my latest attempt at error handler
    Private Sub cmdsearch_Click()
    Dim a As String
    Dim b As String
    Dim c As String
    Dim answer As String
    Dim answer2 As String
    
    
        On Error GoTo ErrorHandler
    Top:
     
     
    
    
    If obtclient.Value = True Then
    a = Application.WorksheetFunction.VLookup(Worksheets("INPUT").Range("B1"), Worksheets("Outlook Info").Range("a1:C10000"), 2, False)
    
    
    txtCname = txtsearch
    txtAlais = a
    txtphone = Application.WorksheetFunction.VLookup(Worksheets("INPUT").Range("B1"), Worksheets("Outlook Info").Range("a1:c10000"), 3, False)
    ElseIf optalias.Value = True Then
    b = Application.WorksheetFunction.VLookup(Worksheets("INPUT").Range("B1"), Worksheets("Outlook Info").Range("D1:F10000"), 3, False)
    txtAlais.Value = txtsearch
    txtCname = b
    txtphone = Application.WorksheetFunction.VLookup(Worksheets("INPUT").Range("B1"), Worksheets("Outlook Info").Range("D1:F10000"), 2, False)
    
    Else
    optphone.Value = True
    c = Application.WorksheetFunction.VLookup(Worksheets("INPUT").Range("B1"), Worksheets("Outlook Info").Range("g1:I10000"), 2, False)
    
     
    txtphone = txtsearch
    txtCname = c
    txtAlais = Application.WorksheetFunction.VLookup(Worksheets("INPUT").Range("B1"), Worksheets("Outlook Info").Range("g1:I10000"), 3, False)
    
    End If
    ErrorHandler:
    
    
    
    MsgBox "Nothing found"
    
    GoTo Top
    
    
     'End If
     lblstartup.Visible = False
     lblstartup2.Visible = False
     
     lbldate.Visible = True
    txtdate.Visible = True
    'Frame3.Visible = False
    Frame2.Visible = True
    Frame5.Visible = True
    lblissue.Visible = True
    txtissue.Visible = True
    cmdsi.Visible = True
    lbltitle.Visible = True
    txttitle.Visible = True
    lblsystem.Visible = True
    txtsystem.Visible = True
    lblcomponent.Visible = True
    txtcomp.Visible = True
    lblitem.Visible = True
    txtitem.Visible = True
    Label4.Visible = True
    txtassign.Visible = True
    lbldescription.Visible = True
    txtdescription.Visible = True
    Label5.Visible = True
    txtsolution.Visible = True
     
    
    
    Resume Next
    
    
    
    
    
    
    
    
    End Sub

  13. #13
    Registered User
    Join Date
    12-05-2008
    Location
    Ottawa
    Posts
    82
    what I am trying to do is prevent a run-time error to happenif the vlookup doesn't find what the user is searching for

  14. #14
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    Did you try replacing all the VLOOKUPS with.Find?

  15. #15
    Registered User
    Join Date
    12-05-2008
    Location
    Ottawa
    Posts
    82
    yes but no luck

  16. #16
    Registered User
    Join Date
    12-05-2008
    Location
    Ottawa
    Posts
    82
    how would I return the value from the next row example someone searches for Pete Peterson than there alais will appear and so will there extension ?

  17. #17
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    Dim cl     As Range
        If obtclient.Value = True Then
    
            Set cl = Worksheets("Outlook Info").Range("b1:b10000").Find(Worksheets("INPUT").Range("B1").Value, LookIn:=xlValues)
            If cl Is Nothing Then
                MsgBox "Not there"
                'do something else
            Else: a = cl.Value
               b=cl.offset(1,0).Value
                txtCname = txtsearch
                txtAlais = a
            End If
            'etc
    You probably need to attach the workbook.
    Last edited by royUK; 01-12-2009 at 10:34 AM.

  18. #18
    Registered User
    Join Date
    12-05-2008
    Location
    Ottawa
    Posts
    82
    I just retried it not sure how to get the value in the next row like a vlookup

  19. #19
    Registered User
    Join Date
    12-05-2008
    Location
    Ottawa
    Posts
    82
    tried this sort of working what I want is the value next to it not bekow it

  20. #20
    Registered User
    Join Date
    12-05-2008
    Location
    Ottawa
    Posts
    82
    cool starting to work better I did this
     txtphone = cl.Offset(0, 1).Value

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1