Duplicate declaration in current scope

dcollard23

Registered User.
Local time
Today, 07:36
Joined
Jun 15, 2009
Messages
87
Hello,
I am getting a duplicate declaration in current scope error. How do I fix it.

Sub SetupTargetDate()
On Error GoTo ErrorHandler

Dim dtTime As Date
Dim dtTemp As Date


If IsNull(Me.Date) Then Exit Sub
If IsNull(Me.Time_Received) Then Exit Sub

dtTime = Nz(Me.[Time Received])
If Nz(Me.cboTransactionType) = "Endorsement" Then
'fAddOneBusinessDay(dtTemp
dtTime = Nz(Me.[Time Received])
If (dtTime > CDate("3:00 PM") And dtTime <= ("11:59:59 PM") Or dtTime >= CDate("12:00 AM") And dtTime <= ("7:59:59 AM")) And Not IsNull(Me.[Time Received]) Then
dtTemp = Me.Date + 1
Me.TMG_Target_Time = CDate("8 AM")
Sub SetupTargetDate()
On Error GoTo ErrorHandler

Dim dtTime As Date
Dim dtTemp As Date


If IsNull(Me.Date) Then Exit Sub
If IsNull(Me.Time_Received) Then Exit Sub

dtTime = Nz(Me.[Time Received])
If Nz(Me.cboTransactionType) = "Endorsement" Then
'fAddOneBusinessDay(dtTemp
dtTime = Nz(Me.[Time Received])
If (dtTime > CDate("3:00 PM") And dtTime <= ("11:59:59 PM") Or dtTime >= CDate("12:00 AM") And dtTime <= ("7:59:59 AM")) And Not IsNull(Me.[Time Received]) Then
dtTemp = Me.Date + 1
Me.TMG_Target_Time = CDate("8 AM")
TryAgain:
If Weekday(dtTemp) = 7 Then
dtTemp = dtTemp + 2
GoTo TryAgain
ElseIf Weekday(dtTemp) = 1 Then
dtTemp = dtTemp + 1
ElseIf DCount("*", "tblHolidays", "[holidaydate]=#" & dtTemp & "#") > 0 Then
dtTemp = dtTemp + 1
GoTo TryAgain
End If

Me.TMG_Target_Date = fAddBusinessDay(dtTemp, 2) '48 additional work hours
' If dtTemp > Me.Date Then
' Me.TMG_Target_Time = Me.[Time Received]
' End If
Else
Me.TMG_Target_Date = fAddBusinessDay(Me.Date, 2) '48 hours
Me.TMG_Target_Time = Me.[Time Received]
End If
Else
MsgBox "Unknown transaction type: " & Me.cboTransactionType
Exit Sub
End If

If Nz(Me.cboTransactionType) = "Cancellation" Or Nz(Me.cboTransactionType) = "Reinstatement" Or Nz(Me.cboTransactionType) = "Bureau Criticism" Then
dtTime = Nz(Me.[Time Received])
If (dtTime > CDate("3:00 PM") And dtTime <= ("11:59:59 PM") Or dtTime >= CDate("12:00 AM") And dtTime <= ("7:59:59 AM")) And Not IsNull(Me.[Time Received]) Then
dtTemp = Me.Date + 1
Me.TMG_Target_Time = CDate("8 AM")
TryAgain:
If Weekday(dtTemp) = 7 Then
dtTemp = dtTemp + 2
GoTo TryAgain
ElseIf Weekday(dtTemp) = 1 Then
dtTemp = dtTemp + 1
ElseIf DCount("*", "tblHolidays", "[holidaydate]=#" & dtTemp & "#") > 0 Then
dtTemp = dtTemp + 1
GoTo TryAgain
End If

Me.TMG_Target_Date = fAddBusinessDay(dtTemp, 3) '72 additional work hours
' If dtTemp > Me.Date Then
' Me.TMG_Target_Time = Me.[Time Received]
' End If
Else
Me.TMG_Target_Date = fAddBusinessDay(Me.Date, 3) '72 hours
Me.TMG_Target_Time = Me.[Time Received]
End If
Else
MsgBox "Unknown transaction type: " & Me.cboTransactionType
Exit Sub
End If

If IsNull(Me.TMG_Target_Date) Then Exit Sub

CheckForHolidays:
If Weekday(Me.TMG_Target_Date) = 1 Then
Me.TMG_Target_Date = fAddBusinessDay(Me.TMG_Target_Date, 1)
End If
If Weekday(Me.TMG_Target_Date) = 7 Then
Me.TMG_Target_Date = fAddBusinessDay(Me.TMG_Target_Date, 2)
End If
If DCount("HolidayDate", "tblHolidays", "[HolidayDate]=#" & Me.TMG_Target_Date & "#") > 0 Then
Me.TMG_Target_Date = fAddBusinessDay(Me.TMG_Target_Date, 1)
GoTo CheckForHolidays
End If

'Me.Target_Time = Me.[Time Received]


Exit Sub
ErrorHandler:
MsgBox Err.Description
End Sub



Thanks for your assistance
Elaine
 
Is that the actual code? The Sub starts over about 10 lines down.
 
Yes, because the transaction types were different so I thought I had to repeat the code again.
I don't know much about code so any help will be greatly appreciated.

Thanks.
 
For starters, each function/sub must stand alone:

Code:
Sub Whatever
  'some code here
End Sub

Function Whoever
  'other code here
End Function

You have

Code:
Sub SetupTargetDate()
  'some code
Sub SetupTargetDate()
  'more code
End Sub
 
This part of the code will be different depending on the transaction type:
dtTemp cound be 1 or 3
Me.TMG_Target_Date = fAddBusinessDay(dtTemp, 2) '48 additional work hours
' If dtTemp > Me.Date Then
' Me.TMG_Target_Time = Me.[Time Received]
' End If
Else
Me.TMG_Target_Date = fAddBusinessDay(Me.Date, 2) '48 hours
Me.TMG_Target_Time = Me.[Time Received]
End If


but all the other code will be the same. I do not know how to arrange it though to where it is not repeating itself.

Thanks for your advance assistance.
Elaine
 
I don't understand, and frankly the code is confusing. You say it could be 1 or 3 but the code seems to treat it like a date. In any case, typically you'd handle different treatments with logical statements like If/Then.
 

Users who are viewing this thread

Back
Top Bottom