Run-Time error '13' Type Mismatch

ddrew

seasoned user
Local time
Today, 12:40
Joined
Jan 26, 2003
Messages
911
Hi im getting an error on a line from my export code, but I cant figure out whats wrong. The line in red is wheer the debug points to.

Code:
Private Sub btnExportTrainingRecord_Click()
    Dim strday As String    'The date
    Dim sDest As String    'Where the file will be copied to
    Dim sSource As String    'The name of the file to be copied

    Dim strBackUpDir As String
    Dim strBackUpFolder As String
    Dim strBackUpDogNameFolder As String

    Dim strDogName As String    'The name of the dog that is geting exported


    strBackUpDir = "c:\GPandDetectionDogTrainingLogBackUp\"
    strBackUpFolder = "c:\GPandDetectionDogTrainingLogBackUp\Training"
    strBackUpDogNameFolder = "c:\GPandDetectionDogTrainingLogBackUp\Training\" & Forms![frm_Profile]![DogName]

    If Len(Dir(strBackUpDir, vbDirectory)) = 0 Then
        MkDir strBackUpDir
    End If

    If Len(Dir(strBackUpFolder, vbDirectory)) = 0 Then
        MkDir strBackUpFolder
    End If

    If Len(Dir(strBackUpDogNameFolder, vbDirectory)) = 0 Then
        MkDir strBackUpDogNameFolder
    End If


    Shell "EXPLORER.EXE " & strBackUpDogNameFolder, vbNormalFocus

    strday = Format(Now(), "_yyyy_mm_dd")
    [COLOR="Red"]sSource = "c:\GPandDetectionDogTrainingLogBackUp\Training\GPandDetectionDogTrainingLogBackUpTraining\" & strBackUpDogNameFolder \ "GPandDetectionDogTrainingLogBackUpTraining"[/COLOR]
strDogName = Forms![frm_Profile]![DogName]
    sDest = "c:\GPandDetectionDogTrainingLogBackUp\Training\GPandDetectionDogTrainingLogBackUpTraining\" & strBackUpDogNameFolder \ "GPandDetectionDogTrainingLogBackUpTraining" & strDogName & strday & ".xls"

    'Copies the files to Excel
    DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "qry_DetectionTraining", "c:\GPandDetectionDogTrainingLogBackUp\Training\" & strBackUpDogNameFolder \ "GPandDetectionDogTrainingLogBackUpTraining.xls", True

    'Copies and renames the file
    FileCopy sSource, sDest

End Sub
 
I haven't studied your code but perhaps it should be:
sSource = "c:\GPandDetectionDogTrainingLogBackUp\Training\GPandDetectionDogTrainingLogBackUpTraining\" & strBackUpDogNameFolder & "\GPandDetectionDogTrainingLogBackUpTraining"
 
Well that worked but I now have a problem in as far as it wont create the file, the debug comes up on this line

Code:
    DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "qry_DetectionTraining", "c:\GPandDetectionDogTrainingLogBackUp\Training\" & strBackUpDogNameFolder & "\GPandDetectionDogTrainingLogBackUpTraining.xls", True
 
Does it give any message or error number

Yes, sorry,

Run-time error '3436':
Failure creating file

Each of the folders gets created (if they havent been already) but the actual spreadsheet isnt.

I've complicated it a bit by each dog having its own backup (there is a reason for this. When I was puting all the backups in one directory it was working.
 
Try:
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "qry_DetectionTraining", "c:\GPandDetectionDogTrainingLogBackUp\Training\'" & Forms![frm_Profile]![DogName]& "'\GPandDetectionDogTrainingLogBackUpTraining.xls", True
 
Well I just noticed one error, I had the wrong path, but Im still getting the same error! Code should be:
Code:
    DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "qry_DetectionTraining", "c:\GPandDetectionDogTrainingLogBackUp\Training\" & strBackUpDogNameFolder & "\GPandDetectionDogTrainingLogBackUpTraining.xls", True
 
Try:
Code:
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "qry_DetectionTraining", "c:\GPandDetectionDogTrainingLogBackUp\Training\'" & strBackUpDogNameFolder & "'\GPandDetectionDogTrainingLogBackUpTraining.xls", True
 
Try:
Code:
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "qry_DetectionTraining", "c:\GPandDetectionDogTrainingLogBackUp\Training\'" & strBackUpDogNameFolder & "'\GPandDetectionDogTrainingLogBackUpTraining.xls", True

Same runtime error
 
Put this line of code:
Debug.Print "c:\GPandDetectionDogTrainingLogBackUp\Training\'" & strBackUpDogNameFolder & "'\GPandDetectionDogTrainingLogBackUpTraining.xls"
immediately before the DoCmd.TransferSpreadsheet line of code that is throwing the error. When the code breaks, open the immediate window and post back with it's contents.
 
Put this line of code:
Debug.Print "c:\GPandDetectionDogTrainingLogBackUp\Training\'" & strBackUpDogNameFolder & "'\GPandDetectionDogTrainingLogBackUpTraining.xls"
immediately before the DoCmd.TransferSpreadsheet line of code that is throwing the error. When the code breaks, open the immediate window and post back with it's contents.

Sorry for the delay
Here is the code from the Immediate Window

Code:
c:\GPandDetectionDogTrainingLogBackUp\Trainin c:\GPandDetectionDogTrainingLogBackUp\Training\'c:\GPandDetectionDogTrainingLogBackUp\Training\Chester'\GPandDetectionDogTrainingLogBackUpTraining. xls
g\'c:\GPandDetectionDogTrainingLogBackUp\Training\Chester'\GPandDetectionDogTrainingLogBackUpTraining. xls
 
Perhaps you can see the problem now. The string used is invalid. What result do you get with:
Debug.Print strBackUpDogNameFolder
 
I get this:

Code:
c:\GPandDetectionDogTrainingLogBackUp\Training\Chester

I'm not sure why its invalid though.
 
Perhaps this will work:

DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "qry_DetectionTraining", strBackUpDogNameFolder & "\GPandDetectionDogTrainingLogBackUpTraining.xls", True
 
Nearly, its created the file, but now errors on the line:
Code:
FileCopy sSource, sDest
Run-time error '52'
Bad file name or number

The Immediate Windo shows this:

c:\GPandDetectionDogTrainingLogBackUp\Training\Chester
 
Last edited:
Figured it out, it was the two strings sDest and sSource, tey wernt quite the same. Many thanks for your time.
 

Users who are viewing this thread

Back
Top Bottom