M
mi
Hi folks
I am trying to read data from a file and put in my database. I’ve
removed lots of sentences and tried to save only the most important
stuff.
The Sub goes fine as well as the function. I get no errors, what so
ever. The data in the Insert line looks just as I want it.
Still the database looks exactly as it did before.
Can someone please give me a hint of what I’ve missed or done wrong.
Thanks in advance
/Michelle
(e-mail address removed)
Private Sub cmdImport_Click()
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, ,
acMenuVer70
DoCmd.GoToRecord , , acNewRec
RunTheImport
Exit_cmdImport_Click:
'MsgBox "New magasine saved"
Exit Sub
End Sub
----------------
Option Compare Database
Function RunTheImport()
ny = True
Set db = CurrentDb()
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 contains just
headers)
Line Input #intFile, strLine
Do While Not EOF(intFile)
Line Input #intFile
varArray = Split(strLine, ";")
date = varArray(0)
photoId = varArray(1)
description = varArray(2)
magasineName = varArray(3)
If (ny = True) Then
boxId = DMax("boxId", "Photos", "")
magasineId = "A"
boxId = boxId + 1
pictureId = 1
rowid = DMax("rowId", "Photos", "")
rowid = rowid + 1
ny = False
Else
rowid = rowid + 1
pictureId = pictureId + 1
End If
'rowid = highestRowid + 1
SQLstr2 = "INSERT INTO Photos ( rowId, boxId,
magasineName, description, photoId, pictureId, magasineId) VALUES(" &
_
rowid & ", " & boxId & ", '" & magasineName & "',
'" & description & "', " & photoId & ", " & pictureId & ", '" &
magasineId & "'); "
CurrentDb.Execute SQLstr2
Loop
Close #intFile
'dbs.Close
'Set dbs = Nothing
Exit_RunTheImport:
Exit Function
Err_RunTheImport:
'Debug.Print Forms("Order Entry").OnInsert
MsgBox Err.description
End Function
I am trying to read data from a file and put in my database. I’ve
removed lots of sentences and tried to save only the most important
stuff.
The Sub goes fine as well as the function. I get no errors, what so
ever. The data in the Insert line looks just as I want it.
Still the database looks exactly as it did before.
Can someone please give me a hint of what I’ve missed or done wrong.
Thanks in advance
/Michelle
(e-mail address removed)
Private Sub cmdImport_Click()
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, ,
acMenuVer70
DoCmd.GoToRecord , , acNewRec
RunTheImport
Exit_cmdImport_Click:
'MsgBox "New magasine saved"
Exit Sub
End Sub
----------------
Option Compare Database
Function RunTheImport()
ny = True
Set db = CurrentDb()
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 contains just
headers)
Line Input #intFile, strLine
Do While Not EOF(intFile)
Line Input #intFile
varArray = Split(strLine, ";")
date = varArray(0)
photoId = varArray(1)
description = varArray(2)
magasineName = varArray(3)
If (ny = True) Then
boxId = DMax("boxId", "Photos", "")
magasineId = "A"
boxId = boxId + 1
pictureId = 1
rowid = DMax("rowId", "Photos", "")
rowid = rowid + 1
ny = False
Else
rowid = rowid + 1
pictureId = pictureId + 1
End If
'rowid = highestRowid + 1
SQLstr2 = "INSERT INTO Photos ( rowId, boxId,
magasineName, description, photoId, pictureId, magasineId) VALUES(" &
_
rowid & ", " & boxId & ", '" & magasineName & "',
'" & description & "', " & photoId & ", " & pictureId & ", '" &
magasineId & "'); "
CurrentDb.Execute SQLstr2
Loop
Close #intFile
'dbs.Close
'Set dbs = Nothing
Exit_RunTheImport:
Exit Function
Err_RunTheImport:
'Debug.Print Forms("Order Entry").OnInsert
MsgBox Err.description
End Function