Importing from Excel into table (1 Viewer)

HV_L

Registered User.
Local time
Today, 06:58
Joined
Dec 23, 2009
Messages
53
Hi all,
Got a problem with a office 2007 user.
The database which holds this code, is used by different people using different Office versions.. (yes, I know...)
Anyone knows how to solve the problem?
The error is referring to the acSpreadsheetTypeExcel3 part.


Code:
Private Sub ImportDeelnemer_Click()
On Error GoTo Err_ImportDeelnemer_Click

If MsgBox("U staat op het punt om de Deelnemers Tabel te vervangen" _
& vbCrLf & "middels deze Importfunctie." & vbCrLf & "Weet U dit zeker?", _
vbYesNo, "Import van Deelnemerstabel") = vbYes Then _

Dim ImportFile As String
Dim Import As String


'Waarschuwingen uitzetten
DoCmd.SetWarnings False

'Oude copy verwijderen
On Error GoTo Import
DoCmd.DeleteObject acTable, "deelnemer_copy"

Import:
'Temp tabel maken waarnaar je je gegevens importeert
DoCmd.CopyObject , "Deelnemer_copy", acTable, "Deelnemer"

'Temp tabel weer leegmaken
DoCmd.RunSQL "DELETE * FROM Deelnemer_copy"

'Gegevens importeren in temp tabel
ImportFile = Application.CurrentProject.Path & "\Deelnemer.xls"
DoCmd.TransferSpreadsheet acImport,[B] acSpreadsheetTypeExcel3, [/B]"Deelnemer_copy", ImportFile, True

'Nieuwe records opnemen
DoCmd.RunSQL "INSERT INTO Deelnemer" _
& " SELECT * FROM Deelnemer_copy" _
& " WHERE Deelnemer_copy.Id NOT IN" _
& " (SELECT Deelnemer.Id FROM Deelnemer);"

'Tabel deelnemer bijwerken
    'is ook een Query voorhanden
        'DoCmd.OpenQuery "UpdateDeelnemer", , acReadOnly
'Bij voorkeur via deze code
DoCmd.RunSQL "UPDATE Deelnemer INNER JOIN Deelnemer_copy" _
& " ON Deelnemer.Id = Deelnemer_copy.Id" _
& " SET Deelnemer.Naam = Deelnemer_Copy.Naam," _
& " Deelnemer.ASNNR = Deelnemer_Copy.ASNNR," _
& " Deelnemer.URL = Deelnemer_Copy.URL," _
& " Deelnemer.Vereniging= Deelnemer_Copy.Vereniging," _
& " Deelnemer.Adres = Deelnemer_Copy.Adres," _
& " Deelnemer.Postcode = Deelnemer_Copy.Postcode," _
& " Deelnemer.Woonplaats = Deelnemer_Copy.Woonplaats," _
& " Deelnemer.Telnr = Deelnemer_Copy.Telnr," _
& " Deelnemer.Email = Deelnemer_Copy.Email;"

'Waarschuwingen weer aanzetten
DoCmd.SetWarnings True
  
MsgBox "De originele tabel Deelnemer is gekopieerd naar Deelnemer_copy." & vbCrLf & _
"Indien er een foutmelding is verschenen controleer dan de gegevens" & vbCrLf & _
"van het geimporteerde Excelbestand met de nieuwe tabel Deelnemer.", _
vbExclamation, "Check Data"
Else
 MsgBox "Import deelnemers gestopt", , "Geen kopie gemaakt"
End If

Exit_ImportDeelnemer_Click:
    Exit Sub

Err_ImportDeelnemer_Click:
    MsgBox Err.Description
    Resume Exit_ImportDeelnemer_Click
    
End Sub
 

JamesMcS

Keyboard-Chair Interface
Local time
Today, 05:58
Joined
Sep 7, 2009
Messages
1,819
Has this code worked previously? a Type 3 spreadsheet is quite an old version, have you checked the version number of Deelnemer.xls? And what specifically is the error message you're getting?
 

HV_L

Registered User.
Local time
Today, 06:58
Joined
Dec 23, 2009
Messages
53
Yes, this has worked for quite some time.
The error says that the Excel file is not in the right format..
I also tried other acSpreadsheetTypeExcel types but all gave error..
Got no clue how to proceed..
 

JamesMcS

Keyboard-Chair Interface
Local time
Today, 05:58
Joined
Sep 7, 2009
Messages
1,819
Hmmm... is the spreadsheet opening OK by itself? Could it be corrupted? Stumped otherwise....
 

JamesMcS

Keyboard-Chair Interface
Local time
Today, 05:58
Joined
Sep 7, 2009
Messages
1,819
OK - so I guess it's something PC-specific then. What's the exact error massage and error number?
 

Users who are viewing this thread

Top Bottom