I belive it's time to show the whole function.
Maby you'll find somethinh else that is completely wrong.
Thanks for helping me
/Michelle
-----------------------------------------------
Option Compare Database
IFunction RunTheImport()
On Error GoTo Err_RunTheImport
Dim intFile As String
Dim intFields As String
Dim strFile As String
Dim strLine As String
Dim strDir As String
Dim varArray As Variant
Dim MyArray(1 To 4) As String
Dim strPathFile As String
Dim strPath As String
Dim theStr As String
Dim file As String
Dim blnHasFieldNames As Boolean
Dim strSQLImport As String
Dim tblImportToSplit As String
Dim rstImport As Recordset
Dim lngLoop As Long
Dim varFields As Variant
Dim varIN As Variant
Dim strBuffer As String
Dim pstrPathFile As String
Dim check As Variant
Dim magasineId As Variant
Dim rowid As Variant
Dim Datum As Variant
Dim boxId As Variant
Dim SQLstr1 As Variant
Dim SQLstr2 As Variant
Dim ny As Boolean
Dim dbFailOnError As Integer
ny = True
Set db = CurrentDb()
'--- Read data from form
strDir = Forms![importWhat]![dir] & "/"
strFile = Forms![importWhat]![file]
strLine = strDir & strFile & ".txt"
intFile = FreeFile()
Open strLine For Input As #intFile
tblImportToSplit = strLine
'--- Discard the first line in the text file, (it just contains
headers)
Line Input #intFile, strLine
varArray = Split(strLine, ";")
magasineName = varArray(3)
'--- Check if magasineName exists in db
check = DLookup("magasineId", "Photos", "[magasineName] = '" &
strFile & "' ")
Do While EOF(intFile) = False
Line Input #intFile, strLine
varArray = Split(strLine, ";")
Datum = varArray(0)
photoid = varArray(1)
description = varArray(2)
magasineName = varArray(3)
'--- rowId
rowid = DMax("rowId", "Photos", "")
rowid = rowid + 1
'If IsNull([check]) Then
If (ny <> False) Then
ny = False
'--- magasineId
magasineId = "A"
'--- boxId
boxId = DMax("boxId", "Photos", "")
boxId = boxId + 1
'--- pictureId
pictureId = 1
SQLstr1 = "INSERT INTO Photos
(rowId,boxId,magasineId,magasineName,pictureId,photoid) VALUES (" & _
rowid & "," & boxId & ",'" & magasineId & "','" &
magasineName & "'," & pictureId & "," & photoid & ");"
CurrentDb.Execute SQLstr1, dbFailOnError
SQLstr1 = "UPDATE [Photos] set [date] = '" & Datum & "'
where [boxId] = " & boxId & " AND [magasineName] = '" & newMagsineName
& "' AND [magasineId] = '" & magasineId & "' ;"
CurrentDb.Execute SQLstr1, dbFailOnError
ny = False
check = 2
Else
'--- pictureId
pictureId = pictureId + 1
SQLstr1 = "INSERT INTO Photos
(rowId,boxId,magasineId,magasineName,pictureId,photoid) VALUES (" & _
rowid & "," & boxId & ",'" & magasineId & "','" &
magasineName & "'," & pictureId & "," & photoid & ");"
'CurrentDb.Execute SQLstr1
CurrentDb.Execute SQLstr1, dbFailOnError
SQLstr2 = "UPDATE [Photos] set [date] = '" & Datum & "'
where [boxId] = " & boxId & " AND [magasineName] = '" & newMagsineName
& "' AND [magasineId] = '" & magasineId & "' ;"
'CurrentDb.Execute SQLstr2
CurrentDb.Execute SQLstr1, dbFailOnError
End If
'End If
Loop
Close #intFile
db.Close
Set db = Nothing
'Set dbs = Nothing
Exit_RunTheImport:
Exit Function
Err_RunTheImport:
'MsgBox Err.description
Resume Exit_RunTheImport
End Function