Best way to skip over code (with Goto?)


I am writing a function that checks two fields.  If they are both null, I wan the function to return "".  If not, I want the function to perform some code on the field and return the value.  What's the best way to have the function skip over the second if then code block if both of the fields are null.  Right now I have a Goto Statement but it's giving me an error.
Option Compare Database

Function findPos(strPassedString As String, iNum As Integer, FindThis As String) As Integer

findPos = 0

While Len(strPassedString) And (iNum > 0)
    If InStr(1, strPassedString, FindThis) Then
        findPos = findPos + InStr(1, strPassedString, FindThis)
        strPassedString = Mid(strPassedString, InStr(1, strPassedString, FindThis) + 1)
        iNum = iNum - 1
    Else
        findPos = 0
        Exit Function
    End If
Wend

If iNum Then findPos = 0

End Function

Function FirstOfMonth(DateInput) As Date
Dim FirstDayOfMonth As String, TwoDigitMonth As String
TwoDigitMonth = IIf(Len(Month(DateInput)) = 1, "0", "") & Month(DateInput)
FirstDayOfMonth = TwoDigitMonth & "/1/" & Year(DateInput)
FirstOfMonth = CDate(FirstDayOfMonth)
End Function

Function dolsAdjust(txnType)
Select Case txnType
Case "Bill"
dolsAdjust = 1
Case "Bill Pmt -Check"
dolsAdjust = -1
Case Else
dolsAdjust = 1
End Select
End Function

Function dolsAdjust2(txnAmt, txnType2, txnType3)
Dim placeholder As Integer
If txnType2 = "Bill" Then
placeholder = 1
ElseIf txnType2 = "Journal" And txnType3 = "Accounts Trade Payables" Then
placeholder = -1
Else
placeholder = 0
End If

dolsAdjust2 = txnAmt * placeholder
End Function

Function FindDept(AccountRef1, AccountRef2)
Dim colonPos As Integer
Dim AccountRefToUse As String
Dim TextToRight As String

If IsNull([AccountRef1]) And IsNull([AccountRef2]) Then
    FindDept = ""
End If
GoTo EndOfSection
If AccountRef1 = "" Then
   AccountRefToUse = AccountRef2
Else
   AccountRefToUse = AccountRef1
End If

colonPos = InStr([AccountRefToUse], ":")
TextToRight = Right([AccountRefToUse], Len([AccountRefToUse]) - colonPos)

If colonPos = 0 Then
FindDept = [AccountRefToUse]
Else
FindDept = TextToRight
End If
EnndofSection:
End Function

Open in new window

BBluAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Saqib Husain, SyedEngineerCommented:
you need to correct the spelling of the goto target

change the last line from

EnndofSection:

to

EndofSection:
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
BBluAuthor Commented:
Thanks ssaqibh.  I don't know how I missed that.  I guess until I get better, I'm going to assume something's wrong with my code..other than a typo. Thanks for the simple and quick solution.
0
Saqib Husain, SyedEngineerCommented:
Maybe this is what you should have

Function FindDept(AccountRef1, AccountRef2)
Dim colonPos As Integer
Dim AccountRefToUse As String
Dim TextToRight As String

If IsNull([AccountRef1]) And IsNull([AccountRef2]) Then
    FindDept = ""
Else
    If AccountRef1 = "" Then
       AccountRefToUse = AccountRef2
    Else
       AccountRefToUse = AccountRef1
    End If
   
    colonPos = InStr([AccountRefToUse], ":")
    TextToRight = Right([AccountRefToUse], Len([AccountRefToUse]) - colonPos)
   
    If colonPos = 0 Then
        FindDept = [AccountRefToUse]
    Else
        FindDept = TextToRight
    End If
End If
End Function
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.