Gandalf_One
New member
- Local time
- Today, 18:32
- Joined
- Nov 27, 2012
- Messages
- 5
I am running the following VB script and keep getting a 'Runtime Error 13 - Type Mismatch'. The code is below. The type mismatch is occurring on intspan1 = ![span]
![span] is a number from the table. intspan1 is defined as a long integer. I have tried defining intspan1 as an integer, a variant, even a string - always the same error. I have also tried compact and repair but always the same error.
Please take a look at my code below, perhaps I am missing something.
Any advice would be very much appreciated.
Thanks!!
Dim db As Database
Dim rsPriorPension As DAO.Recordset
Dim rsServiceNo As DAO.Recordset
Dim rsLoad As DAO.Recordset
Dim strSN As String
Dim strSource1 As String
Dim strSource2 As String
Dim strSource3 As String
Dim strCCode1 As Long
Dim strCCode2 As Long
Dim strCCode3 As Long
Dim intspan1 As Long
Dim intspan2 As Long
Dim intspan3 As Long
Dim strCCPSflg1 As String
Dim strCCPSflg2 As String
Dim strHRMSflg As String
Dim dbchgnum As Long
On Error GoTo ErrorHandler
strSN = ""
dbchgnum = 4
spancnt1 = 0
'Initialize database and recordset values
Set db = CurrentDb()
Set rsServiceNo = db.OpenRecordset("qryDistinctServiceNumber_extract")
Set rsLoad = db.OpenRecordset("child_tblPriorPension")
'Initialize Variables
'Loop through all service numbers
With rsServiceNo
If .RecordCount > 0 Then
.MoveFirst
Do Until .EOF
strSN = ![ServiceNo]
Debug.Print strSN
Set rsPriorPension = db.OpenRecordset("Select * from tblMergedExtract where ServiceNo = '" & strSN & "' ORDER BY tblMergedExtract.ServiceNo, tblMergedExtract.Span, tblMergedExtract.Source;")
With rsPriorPension 'Loop through records with matching Service numbers
If .RecordCount = 3 Then
.MoveFirst
Do Until .EOF 'Apply conditions to selected data
Debug.Print spancnt1
If strSN = ![ServiceNo] Then
If ![Source] = "CCPS" Then
strSource1 = ![Source] And intspan1 = ![Span] And strCCode1 = ![ComponentCode] And strCCPSflg1 = "Yes"
End If
If ![Source] = "HRMS" Then
strSource2 = ![Source] And intspan2 = ![Span] And strCCode2 = ![ComponentCode] And strHRMSflg = "Yes"
End If
If ![Source] = "CCPS" And ![ComponentCode] = "2" And ![RelDate] < #1/3/2007# Then
strSource3 = ![Source] And strCCode3 = ![ComponentCode] And strCCPSflg2 = "Yes"
End If
End If
.MoveNext
Loop
If strCCPSflg1 = "Yes" And strHRMSflg = "Yes" And strCCPSflg2 = "Yes" Then
If intspan2 = intspan1 And strCCode2 = strCCode1 Then
.MoveFirst
Do Until .EOF
'Move data that matches criteria to child table
rsLoad.AddNew
rsLoad("ID") = ![ID]
rsLoad("ServiceNo") = ![ServiceNo]
rsLoad("Source") = ![Source]
rsLoad("ComponentCode") = ![ComponentCode]
rsLoad("EnrolDate") = ![EnrolDate]
rsLoad("RelDate") = ![RelDate]
rsLoad("RelReason") = ![RelReason]
rsLoad("UIC") = ![UIC]
rsLoad("Merged") = ![Merged]
rsLoad("Span") = ![Span]
rsLoad("DataChange") = dbchgnum
rsLoad.Update
.Delete
.MoveNext
Loop
End If
End If
End If
End With
.MoveNext
Loop
End If
End With
rsPriorPension.Close
CCctr = 0
db.Close
Set rsPriorPension = Nothing
Set rsLoad = Nothing
Set db = Nothing
'Call procedure that makes copy of the tblMergedExtract
Call CopyTableMergedExtract(dbchg:=dbchgnum)
Exit Sub
ErrorHandler:
MsgBox "Error #: " & Err.Number & vbCrLf & vbCrLf & Err.Description
End Sub
![span] is a number from the table. intspan1 is defined as a long integer. I have tried defining intspan1 as an integer, a variant, even a string - always the same error. I have also tried compact and repair but always the same error.
Please take a look at my code below, perhaps I am missing something.
Any advice would be very much appreciated.
Thanks!!
Dim db As Database
Dim rsPriorPension As DAO.Recordset
Dim rsServiceNo As DAO.Recordset
Dim rsLoad As DAO.Recordset
Dim strSN As String
Dim strSource1 As String
Dim strSource2 As String
Dim strSource3 As String
Dim strCCode1 As Long
Dim strCCode2 As Long
Dim strCCode3 As Long
Dim intspan1 As Long
Dim intspan2 As Long
Dim intspan3 As Long
Dim strCCPSflg1 As String
Dim strCCPSflg2 As String
Dim strHRMSflg As String
Dim dbchgnum As Long
On Error GoTo ErrorHandler
strSN = ""
dbchgnum = 4
spancnt1 = 0
'Initialize database and recordset values
Set db = CurrentDb()
Set rsServiceNo = db.OpenRecordset("qryDistinctServiceNumber_extract")
Set rsLoad = db.OpenRecordset("child_tblPriorPension")
'Initialize Variables
'Loop through all service numbers
With rsServiceNo
If .RecordCount > 0 Then
.MoveFirst
Do Until .EOF
strSN = ![ServiceNo]
Debug.Print strSN
Set rsPriorPension = db.OpenRecordset("Select * from tblMergedExtract where ServiceNo = '" & strSN & "' ORDER BY tblMergedExtract.ServiceNo, tblMergedExtract.Span, tblMergedExtract.Source;")
With rsPriorPension 'Loop through records with matching Service numbers
If .RecordCount = 3 Then
.MoveFirst
Do Until .EOF 'Apply conditions to selected data
Debug.Print spancnt1
If strSN = ![ServiceNo] Then
If ![Source] = "CCPS" Then
strSource1 = ![Source] And intspan1 = ![Span] And strCCode1 = ![ComponentCode] And strCCPSflg1 = "Yes"
End If
If ![Source] = "HRMS" Then
strSource2 = ![Source] And intspan2 = ![Span] And strCCode2 = ![ComponentCode] And strHRMSflg = "Yes"
End If
If ![Source] = "CCPS" And ![ComponentCode] = "2" And ![RelDate] < #1/3/2007# Then
strSource3 = ![Source] And strCCode3 = ![ComponentCode] And strCCPSflg2 = "Yes"
End If
End If
.MoveNext
Loop
If strCCPSflg1 = "Yes" And strHRMSflg = "Yes" And strCCPSflg2 = "Yes" Then
If intspan2 = intspan1 And strCCode2 = strCCode1 Then
.MoveFirst
Do Until .EOF
'Move data that matches criteria to child table
rsLoad.AddNew
rsLoad("ID") = ![ID]
rsLoad("ServiceNo") = ![ServiceNo]
rsLoad("Source") = ![Source]
rsLoad("ComponentCode") = ![ComponentCode]
rsLoad("EnrolDate") = ![EnrolDate]
rsLoad("RelDate") = ![RelDate]
rsLoad("RelReason") = ![RelReason]
rsLoad("UIC") = ![UIC]
rsLoad("Merged") = ![Merged]
rsLoad("Span") = ![Span]
rsLoad("DataChange") = dbchgnum
rsLoad.Update
.Delete
.MoveNext
Loop
End If
End If
End If
End With
.MoveNext
Loop
End If
End With
rsPriorPension.Close
CCctr = 0
db.Close
Set rsPriorPension = Nothing
Set rsLoad = Nothing
Set db = Nothing
'Call procedure that makes copy of the tblMergedExtract
Call CopyTableMergedExtract(dbchg:=dbchgnum)
Exit Sub
ErrorHandler:
MsgBox "Error #: " & Err.Number & vbCrLf & vbCrLf & Err.Description
End Sub