BBlu
asked on
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
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
ASKER