Lrn2Code
Registered User.
- Local time
- Today, 13:03
- Joined
- Dec 8, 2008
- Messages
- 56
Hi,
I've been searching to see if I can find a solution to the problem I'm having - so far I haven't so will take a chance and post my question.
I'm trying to import Excel spreadsheets into an Access database and I keep getting an error on the DoCmd line where it's creating the spreadsheet in the db. It's telling me the path isn't found and the path the error lists isn't even the path I have created to run. Is there some default path the computer always uses? My code follows -
Public Sub import_Floppy()
On Error GoTo err_Import_Floppy
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim rstSchool As DAO.Recordset
Dim qdf As DAO.QueryDef
Dim strSQL As String
Dim strMsg As String
Dim strSch As String
Dim strDelete As String
Dim strUpdate As String
Dim strSD As String
Dim intSch As Long
Dim strSU As String
Dim varAns As Variant
Dim intCnt As Integer
Dim strDistIn As String
Dim strToImp As Variant 'CHANGED FROM STRING TO VARIANT 1-9-09
intCnt = 0
Dim strFileName As String
strFileName = Dir("d:\EdCensus09Export\") 'CHANGED A:\ TO D:\ 10-29-08
'get district id from disk
Select Case Left(strFileName, 1)
Case "T", "J", "U"
strDistIn = Left(strFileName, 4)
If strDistIn = "U022" Then strDistIn = Left(strFileName, 5)
Case "S"
strDistIn = Left(strFileName, 5)
Case Else
MsgBox ("District ID does not appear to be valid. Please check the disk.")
End Select
strDistIn = strDistIn & "_" 'CHANGED A:\ TO D:\ 10-29-08 'REMOVED "d:\" & FROM BEGINNING OF THIS STATEMENT AFTER = 1-9-09
Set dbs = CurrentDb
Dim rstCheck4diSt As DAO.Recordset
''for loading data into a raw file folder on network
Dim strSUFldr As String
Dim strDISTFldr As String
Dim strID As String
Dim dDate As Date
Dim dTime As VbDateTimeFormat
''use to avoid error message when on subsequent SU disks
Dim intSULevel As Integer
intSULevel = 0
DoCmd.Hourglass False
''check that disk contains 6 files
Do Until strFileName = ""
intCnt = intCnt + 1
strFileName = Dir
Loop
If intCnt > 6 Then
strMsg = "There are more than 6 files on this disk. Import will not continue."
MsgBox (strMsg)
Exit Sub
ElseIf intCnt < 6 Then
strMsg = "There are less than 6 files on this disk. Import will not continue."
MsgBox (strMsg)
Exit Sub
End If
'Dim strSQL As String
strSQL = "delete * from exp_c_suemporg"
Set qdf = dbs.CreateQueryDef("", strSQL)
qdf.Execute
strSQL = "delete * from exp_tblposrole"
Set qdf = dbs.CreateQueryDef("", strSQL)
qdf.Execute
strSQL = "delete * from exp_tblschoolclasses"
Set qdf = dbs.CreateQueryDef("", strSQL)
qdf.Execute
strSQL = "delete * from exp_tblteachercourses"
Set qdf = dbs.CreateQueryDef("", strSQL)
qdf.Execute
strSQL = "delete * from exp_tblteacherinfo"
Set qdf = dbs.CreateQueryDef("", strSQL)
qdf.Execute
strSQL = "delete * from exp_tblteamteachers"
Set qdf = dbs.CreateQueryDef("", strSQL)
qdf.Execute
'ADDED CODING TO INCLUDE DATE AND TIME OF DATA LOAD ON FILES
strToImp = strDistIn & "exp_c_suemporg.xls" & "_" & Month(Now()) & "-" & Day(Now()) & "-" & Year(Now()) & "_" & Hour(Now()) & ":" & Minute(Now()) & ":" & Second(Now())
Debug.Print (strToImp)
' COMMENTING OUT TO TRY ABOVE CODE INSTEAD 1-9-09 "(" & CStr(Month(dDate)) & "-" & CStr(Day(dDate)) & "-" & CStr(Year(dDate)) & "_" & CStr(Time(dTime)) & ")"
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel97, strToImp, True
For some reason whenever this code tries to run it stops on the red line above and I get a Microsoft Jet Engine error that the path name isn't found and it lists a C:\Documents and Settings\My Documents (blah blah blah) path. I can't find anywhere in the code where that path is listed. How can I figure out where that path is coming from so I can change it?
Thanks muchly for your guidance!
I've been searching to see if I can find a solution to the problem I'm having - so far I haven't so will take a chance and post my question.
I'm trying to import Excel spreadsheets into an Access database and I keep getting an error on the DoCmd line where it's creating the spreadsheet in the db. It's telling me the path isn't found and the path the error lists isn't even the path I have created to run. Is there some default path the computer always uses? My code follows -
Public Sub import_Floppy()
On Error GoTo err_Import_Floppy
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim rstSchool As DAO.Recordset
Dim qdf As DAO.QueryDef
Dim strSQL As String
Dim strMsg As String
Dim strSch As String
Dim strDelete As String
Dim strUpdate As String
Dim strSD As String
Dim intSch As Long
Dim strSU As String
Dim varAns As Variant
Dim intCnt As Integer
Dim strDistIn As String
Dim strToImp As Variant 'CHANGED FROM STRING TO VARIANT 1-9-09
intCnt = 0
Dim strFileName As String
strFileName = Dir("d:\EdCensus09Export\") 'CHANGED A:\ TO D:\ 10-29-08
'get district id from disk
Select Case Left(strFileName, 1)
Case "T", "J", "U"
strDistIn = Left(strFileName, 4)
If strDistIn = "U022" Then strDistIn = Left(strFileName, 5)
Case "S"
strDistIn = Left(strFileName, 5)
Case Else
MsgBox ("District ID does not appear to be valid. Please check the disk.")
End Select
strDistIn = strDistIn & "_" 'CHANGED A:\ TO D:\ 10-29-08 'REMOVED "d:\" & FROM BEGINNING OF THIS STATEMENT AFTER = 1-9-09
Set dbs = CurrentDb
Dim rstCheck4diSt As DAO.Recordset
''for loading data into a raw file folder on network
Dim strSUFldr As String
Dim strDISTFldr As String
Dim strID As String
Dim dDate As Date
Dim dTime As VbDateTimeFormat
''use to avoid error message when on subsequent SU disks
Dim intSULevel As Integer
intSULevel = 0
DoCmd.Hourglass False
''check that disk contains 6 files
Do Until strFileName = ""
intCnt = intCnt + 1
strFileName = Dir
Loop
If intCnt > 6 Then
strMsg = "There are more than 6 files on this disk. Import will not continue."
MsgBox (strMsg)
Exit Sub
ElseIf intCnt < 6 Then
strMsg = "There are less than 6 files on this disk. Import will not continue."
MsgBox (strMsg)
Exit Sub
End If
'Dim strSQL As String
strSQL = "delete * from exp_c_suemporg"
Set qdf = dbs.CreateQueryDef("", strSQL)
qdf.Execute
strSQL = "delete * from exp_tblposrole"
Set qdf = dbs.CreateQueryDef("", strSQL)
qdf.Execute
strSQL = "delete * from exp_tblschoolclasses"
Set qdf = dbs.CreateQueryDef("", strSQL)
qdf.Execute
strSQL = "delete * from exp_tblteachercourses"
Set qdf = dbs.CreateQueryDef("", strSQL)
qdf.Execute
strSQL = "delete * from exp_tblteacherinfo"
Set qdf = dbs.CreateQueryDef("", strSQL)
qdf.Execute
strSQL = "delete * from exp_tblteamteachers"
Set qdf = dbs.CreateQueryDef("", strSQL)
qdf.Execute
'ADDED CODING TO INCLUDE DATE AND TIME OF DATA LOAD ON FILES
strToImp = strDistIn & "exp_c_suemporg.xls" & "_" & Month(Now()) & "-" & Day(Now()) & "-" & Year(Now()) & "_" & Hour(Now()) & ":" & Minute(Now()) & ":" & Second(Now())
Debug.Print (strToImp)
' COMMENTING OUT TO TRY ABOVE CODE INSTEAD 1-9-09 "(" & CStr(Month(dDate)) & "-" & CStr(Day(dDate)) & "-" & CStr(Year(dDate)) & "_" & CStr(Time(dTime)) & ")"
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel97, strToImp, True
For some reason whenever this code tries to run it stops on the red line above and I get a Microsoft Jet Engine error that the path name isn't found and it lists a C:\Documents and Settings\My Documents (blah blah blah) path. I can't find anywhere in the code where that path is listed. How can I figure out where that path is coming from so I can change it?
Thanks muchly for your guidance!