Results 1 to 4 of 4
  1. #1
    redbull's Avatar
    redbull is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Mar 2012
    Location
    Missouri
    Posts
    480

    With End with If end if On error

    I have a statement that is not always true in my code.



    Code:
      With oServMan.Document.frames(0).Document.all
        Client = .Item("X12").Value
        End With
    The problem is Client could also be

    Code:
      With oServMan.Document.frames(0).Document.all
        Client = .Item("X12").Value
        Client = .Item("X14").Value
        Client = .Item("X18").Value
        End With
    I am having a hard time getting the code to handle this correctly. I want it see if X12 is true, if so continue on.. if not try x14 etc etc. I have tried if statements but have not came up with anything. Also tried error handling, and that worked to an extent, but would ultimately give an error..

    This also will apply to this bit as well


    Code:
      With oServMan.Document.frames(0).Document.all
        ProbLoc = .Item("X57").Value
        End With
    Code:
      With oServMan.Document.frames(0).Document.all
        ProbLoc = .Item("X57").Value
        ProbLoc = .Item("X41").Value
        ProbLoc = .Item("X64").Value
        End With
    Any assistance would be greatly appreciated.

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    How about posting the If statement you used? What if none are true?

  3. #3
    redbull's Avatar
    redbull is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Mar 2012
    Location
    Missouri
    Posts
    480
    The if Statement failed horribly

    Code:
      With oServMan.Document.frames(0).Document.all
        Client = .Item("X12").Value
            If Client = "" Then
           Client = .Item("X14").Value
           End If
            If Client = "" Then
            Client = .Item("X18").Value
            End If
          
      End With
      With oServMan.Document.frames(0).Document.all
        ProbLoc = .Item("X57").Value
            If ProbLoc = "" Then
            ProbLoc = .Item("X41").Value
            End If
            If ProbLoc = "" Then
            ProbLoc = .Item("X64").Value
            End If
    The error handler did sort of work...but VBA gives the same error for both the client and probloc so it does not seem like a very good way of handling it.


    Code:
    On Error GoTo ErrHandler:
    
    
      With oServMan.Document.frames(0).Document.all
        Client = .Item("X12").Value
            
          
      End With
      With oServMan.Document.frames(0).Document.all
        ProbLoc = .Item("X57").Value
      End With
      
    ErrHandler:
          With oServMan.Document.frames(0).Document.all
        Client = .Item("X14").Value
          End With
          With oServMan.Document.frames(0).Document.all
        Client = .Item("X18").Value
          End With
          With oServMan.Document.frames(0).Document.all
        ProbLoc = .Item("X41").Value
          End With
          With oServMan.Document.frames(0).Document.all
        ProbLoc = .Item("X64").Value
          End With
    I know know, it seems like the "X" value should be set as a variable and handled that way... saying this is easy, don't think I have the knowledge to pull it off successfully.

  4. #4
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    You were never testing for the source value not being True. I'm not sure we yet understand what you need.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 5
    Last Post: 03-27-2012, 01:40 PM
  2. Error 0 problem with error checking
    By SemiAuto40 in forum Programming
    Replies: 4
    Last Post: 12-07-2011, 12:21 PM
  3. Replies: 6
    Last Post: 09-28-2011, 09:20 PM
  4. Error 2501 displays with Error handling
    By agent- in forum Programming
    Replies: 13
    Last Post: 08-05-2011, 02:20 PM
  5. Replies: 8
    Last Post: 05-16-2011, 06:01 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums