troubleshooting Question

Data type mismatch

Avatar of goldstar
goldstar asked on
Visual Basic Classic
7 Comments1 Solution226 ViewsLast Modified:
please excuse the mess, i've been commenting things out as i go and it ain't pretty at this point.

I need to search for the existence of a record based on their SSN (text) and Date (date).  I can't get around the error Data Type mismatch.

Thanks!

Dim DB As DAO.Database, CO As DAO.Recordset, RO As DAO.Recordset, Idx As Index
Dim sPerseus_SSN As String
Dim sPerseus_TrainingDate As Date
Dim sPerseus_DateOfTraining As String
'Dim sPerseus_SSN_DateOfTraining As String
Dim SQL As String

Set DB = CurrentDb()
Set CO = DB.OpenRecordset("tblTraining_Perseus", dbOpenDynaset)
Set RO = DB.OpenRecordset("tblTraining", dbOpenDynaset)


CO.MoveLast
CO.MoveFirst


' now loop through source recordset and insert a new training record

Do Until CO.EOF
    sPerseus_SSN = CO![fldSSN]
    sPerseus_TrainingDate = CO![fldTrainingDate]
    'sPerseus_SSN = "fldSSN = '" & CO![fldSSN] & "'"
    'sPerseus_SSN_DateOfTraining = CO![fldSSN] & CO![fldTrainingDate]
    'sPerseus_DateOfTraining = "fldTrainingDate = '" & CO![fldTrainingDate] & "'"
    With RO
        '.MoveFirst
        '.FindFirst sPerseus_SSN
    'SQL = "RO![fldSSN]=" & Chr(39) & "000-00-0000" & Chr(39) & " AND RO!fldTrainingDate=#8/19/2002#"
    'SQL = RO![fldSSN]=" & Chr(39) & "000-00-0000" & Chr(39) & " AND RO!fldTrainingDate=#8/19/2002#"
    '.FindFirst "fldName = '" & Name & "'"
    'SQL = "fldSSN = '" & sPerseus_SSN & "'"
    SQL = "fldSSN = '" & sPerseus_SSN & "'" & " AND fldTrainingDate = '" & sPerseus_TrainingDate & "'"
    '.FindFirst "fldSSN = '" & sPerseus_SSN & "'"
       
      '.FindFirst SQL
    .FindFirst "fldSSN = '" & sPerseus_SSN & "' AND fldTrainingDate = '" & sPerseus_TrainingDate & "'"

        If RO.NoMatch Then
            RO.AddNew
            RO![fldSSN] = CO![fldSSN]
            RO![fldTrainingDate] = CO![fldTrainingDate]
            RO![fldTrainingLength] = CO![fldTrainingLength]
            RO![fldTrainerCode] = CO![fldTrainerCode]
            RO![fldTrainingTypeCode] = CO![fldTrainingTypeCode]
            RO.Update
        End If
    End With
CO.MoveNext
Loop
ASKER CERTIFIED SOLUTION
Balshe

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 7 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 7 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros