Inherited code keeps re-running

  • Thread starter ragtopcaddy via AccessMonster.com
  • Start date
R

ragtopcaddy via AccessMonster.com

I inherited the following code:

Function IsHistSim(Id As String, Type_Flag As String) As Boolean

Dim strSQL As String
Dim rstresults As Recordset
Dim RepoTicket As String
Dim tradescount As Integer

On Error GoTo ErrorProcess

' Change made to allow use on Dev box
'StrSql = " select rs.TicketNo from RepoSensitivity rs, FileControl fc "
& _
' " where rs.SequenceNo = 36876 " & _
' " and rs.TicketNo = ('" & RepoTicket & "') "

If Type_Flag = "TICKETHS" Then
strSQL = " select rs.LinkedTicketNo from Insight_Sensitivity rs " & _
" where ltrim(rtrim(rs.LinkedTicketNo)) = ('" & LTrim(RTrim
(Id)) & "') "
ElseIf Type_Flag = "MBSHS" Then
strSQL = " select rs.SecurityId from Insight_Sensitivity rs " & _
" where ltrim(rtrim(SensitivityType))='INPUTPLSTRIP%' AND rs.
SecurityId = (" & LTrim(RTrim(Id)) & ") "
ElseIf Type_Flag = "HCUT" Then
strSQL = " select rs.SecurityId from Insight_Sensitivity rs " & _
" where ltrim(rtrim(SensitivityType))='HCUT' AND rs.ValueUSD
is not null AND rs.SecurityId = (" & LTrim(RTrim(Id)) & ") "
End If

Set rstresults = dblocal.OpenRecordset(strSQL)

'Exit routine if no records are returned from Insight
If rstresults.RecordCount = 0 Then
rstresults.Close
IsHistSim = False
' Exit Function
GoTo Outtahere
End If

IsHistSim = True
rstresults.Close
Exit Function

ErrorProcess:
IsHistSim = False
rstresults.Close
Exit Function

Outtahere:
End Function

Regardless of whether it executes "Exit Function" or "GoTo Outtahere", the
code immediately steps right back to "Function IsHistSim(Id As String,
Type_Flag As String) As Boolean" and begins execution all over again. I can't
figure out why it doesn't obediently exit or end the function as coded.

Any ideas?
 
D

Dirk Goldgar

ragtopcaddy via AccessMonster.com said:
I inherited the following code:

Function IsHistSim(Id As String, Type_Flag As String) As Boolean

Dim strSQL As String
Dim rstresults As Recordset
Dim RepoTicket As String
Dim tradescount As Integer

On Error GoTo ErrorProcess

' Change made to allow use on Dev box
'StrSql = " select rs.TicketNo from RepoSensitivity rs,
FileControl fc " & _
' " where rs.SequenceNo = 36876 " & _
' " and rs.TicketNo = ('" & RepoTicket & "') "

If Type_Flag = "TICKETHS" Then
strSQL = " select rs.LinkedTicketNo from Insight_Sensitivity
rs " & _ " where ltrim(rtrim(rs.LinkedTicketNo)) =
('" & LTrim(RTrim (Id)) & "') "
ElseIf Type_Flag = "MBSHS" Then
strSQL = " select rs.SecurityId from Insight_Sensitivity rs "
& _ " where
ltrim(rtrim(SensitivityType))='INPUTPLSTRIP%' AND rs.
SecurityId = (" & LTrim(RTrim(Id)) & ") "
ElseIf Type_Flag = "HCUT" Then
strSQL = " select rs.SecurityId from Insight_Sensitivity rs "
& _ " where ltrim(rtrim(SensitivityType))='HCUT' AND
rs.ValueUSD
is not null AND rs.SecurityId = (" & LTrim(RTrim(Id)) & ") "
End If

Set rstresults = dblocal.OpenRecordset(strSQL)

'Exit routine if no records are returned from Insight
If rstresults.RecordCount = 0 Then
rstresults.Close
IsHistSim = False
' Exit Function
GoTo Outtahere
End If

IsHistSim = True
rstresults.Close
Exit Function

ErrorProcess:
IsHistSim = False
rstresults.Close
Exit Function

Outtahere:
End Function

Regardless of whether it executes "Exit Function" or "GoTo
Outtahere", the code immediately steps right back to "Function
IsHistSim(Id As String, Type_Flag As String) As Boolean" and begins
execution all over again. I can't figure out why it doesn't
obediently exit or end the function as coded.

Any ideas?

My first guess is that the function is being called multiple times. How
is it being called? Is it from an event on a form, from a query, or
what? Under some circumstances, form events fire multiple times.
 
R

ragtopcaddy via AccessMonster.com

Thanks Dirk,

It turns out it was called from the criteria (4 times per record) of a query,
which explains why it never exited but kept going from the "Exit Function"
line directly to the "Function IsHistSim" line over and over.

Bill R

Dirk said:
I inherited the following code:
[quoted text clipped - 58 lines]
Any ideas?

My first guess is that the function is being called multiple times. How
is it being called? Is it from an event on a form, from a query, or
what? Under some circumstances, form events fire multiple times.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top