|
-
Mar 5th, 2005, 10:37 AM
#1
Thread Starter
Junior Member
Import data from csv/xls in Access, changing Date props [SOLVED]
Hi guys,
I need to import from xsl or csv file into MSAccess with VBA code.
(Several users have to be able to download the updated file and import the data in their own local copy of MS Access db.)
The data in this file is coming from MySQL db and has a field "Date" i.e "2004-09-18 00:00:00". In the MSAccess table the Date field the notation is 18-09-2004.
How can I do this ?
This is the importing code to update the table:
Any help is much appreciated !!
Private Sub Importwedstrijd_Click()
On Error GoTo Err_Importwedstrijd_Click
If MsgBox("U staat op het punt om de wedstrijd Tabel te vervangen" _
& vbCrLf & "middels deze Importfunctie." & vbCrLf & "Weet U dit zeker?", _
vbYesNo, "Import van wedstrijdtabel") = vbYes Then _
Dim ImportFile As String
Dim Import As String
'DoCmd.SetWarnings False
On Error GoTo Import
DoCmd.DeleteObject acTable, "wedstrijd_copy"
Import:
'Temp tabel maken waarnaar je je gegevens importeert
DoCmd.CopyObject , "wedstrijd_copy", acTable, "wedstrijd"
'Temp tabel weer leegmaken
'DoCmd.RunSQL "DELETE * FROM wedstrijd_copy"
'Gegevens importeren in temp tabel
ImportFile = Application.CurrentProject.Path & "\wedstrijd.csv"
DoCmd.TransferText acImportDelim, , "wedstrijd_copy", ImportFile, True
'Nieuwe records opnemen
DoCmd.RunSQL "INSERT INTO wedstrijd" _
& " SELECT * FROM wedstrijd_copy" _
& " WHERE wedstrijd_copy.Id NOT IN" _
& " (SELECT wedstrijd.Id FROM wedstrijd);"
'Tabel wedstrijd bijwerken
DoCmd.RunSQL "UPDATE wedstrijd INNER JOIN wedstrijd_copy" _
& " ON wedstrijd.Id = wedstrijd_copy.Id" _
& " SET wedstrijd.Naam = wedstrijd_Copy.Naam," _
& " wedstrijd.Plaats = wedstrijd_Copy.Plaats," _
& " wedstrijd.Datum = wedstrijd_Copy.Datum" _
& " AND (Year(wedstrijd_copy.Datum)>2005);"
DoCmd.SetWarnings True
MsgBox "De originele tabel wedstrijd is gekopieerd naar wedstrijd_copy." & vbCrLf & _
"Indien er een foutmelding is verschenen controleer dan de gegevens" & vbCrLf & _
"van het geimporteerde Excelbestand met de nieuwe tabel wedstrijd.", _
vbExclamation, "Check Data"
Else
MsgBox "Import wedstrijd gestopt", , "Geen kopie gemaakt"
End If
Exit_Importwedstrijd_Click:
Exit Sub
Err_Importwedstrijd_Click:
MsgBox Err.Description
Resume Exit_Importwedstrijd_Click
End Sub
Last edited by pookie62; Mar 16th, 2005 at 04:04 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|