Why do I want to get the path when I already know where it
is? Good question. The code is still in the development
stage and may end up somewhere else. I want to extract the
current path so I can use it as part of a prompt in an
input box when I ask the user for the name of a file to
import.
I'm just very surprised that CurDir would lop off the name
of the current directory and only show the parent, since
from what I read in the help it looks like it should do
just what I wanted.
Here's the code. As I say, I'm new at VB, and learning as
I go along ... I appreciate any comments or suggestions.
Sub Payment_Out()
'Put out the "new" payment sample
'Mike 6/02
On Error GoTo ErrHandle
Dim Testing As Boolean
Testing = True
Dim mbTitle As String
mbTitle = "Payment Sample"
Dim ExportSpecName As String
ExportSpecName = "vbtestout Export Specification"
Dim importFileName As String
Dim exportFileName As String
Dim inTableName As String
Dim outTableName As String
Dim mbRetcode As Integer
Dim strSQL As String
Dim db As Database
Dim rs As Recordset
Dim outRecordCount As Long
Dim ThisDir As Variant
ThisDir = CurDir
'This msgbox shows "D:\work\Chase Sample\", instead of
'"D:\work\Chase Sample\payment"???
If Testing Then
mbRetcode = MsgBox("Current directory: " & ThisDir, _
vbInformation + vbOKOnly)
End If
Set db = CurrentDb
GetImportName:
'Get name of file to import
'(At this writing [6/02] this is always an Excel file.)
importFileName = InputBox("Name of file to import", _
mbTitle, CurDir & "\" & "*.xls"

If importFileName = "" Then
GoTo Done
End If
inTableName = InputBox("Table to import into", mbTitle)
If inTableName = "" Then
GoTo Done
End If
'Delete the table if it already exists
'Note we must include err handling below for cases
'where table DOESN'T exist
strSQL = "DROP TABLE " & inTableName
DoCmd.RunSQL (strSQL)
'Do the import
DoCmd.TransferSpreadsheet acImport, , _
inTableName, importFileName, True
'Get output table name
outTableName = InputBox("Name of Output Table", mbTitle)
If outTableName = "" Then
GoTo Done
End If
'Delete the table if it already exists
'Note we must include err handling below for cases
'where table DOESN'T exist
strSQL = "DROP TABLE " & outTableName
DoCmd.RunSQL (strSQL)
'Create the output table
strSQL = "CREATE TABLE " & outTableName & _
" ( phonenum TEXT(21), " & _
"[CFMC SPECIAL] TEXT(1)," & _
"[CFMC TZ] TEXT(2)," & _
"[CFMC GET CASE] TEXT(6)," & _
"[CFMC CB] TEXT(16)," & _
"[CFMC REP] TEXT(4)," & _
"EAcct Text(16)," & _
"ChName Text(107)," & _
"Hphone Text(10)," & _
"DatInt Text(10)," & _
"DatAct Text(10)," & _
"Bucket Text(133)," & _
"SlType Text(2)," & _
"CDN Text(2)," & _
"SlQues Text(3)," & _
"SlMkt Text(2)" & _
"

;"
'Debug.Print strSQL
'Debug.Print
DoCmd.RunSQL (strSQL)
'Populate the output table with sample reformatted
'the way we want it.
strSQL = "INSERT INTO " & outTableName & _
" SELECT mid([Phone Number],2,3) &" & _
" mid([Phone Number],7,3) &" & _
" mid([Phone Number],11,4) AS Phonenum," & _
" mid([Account Number],1,4) &" & _
" mid([Account Number],6,4) &" & _
" mid([Account Number],11,4) &" & _
" mid([Account Number],16,4) AS EAcct," & _
" ucase([Customer's first name]) & ' ' &" & _
" ucase([Customer's Last Name]) AS ChName," & _
" mid([Phone Number],2,3) &" & _
" mid([Phone Number],7,3) &" & _
" mid([Phone Number],11,4) AS Hphone," & _
" format(Month([Date/Time Received]),'00') & '/' &" & _
" format(Day([Date/Time Received]),'00') & '/' &" & _
" Year([Date/Time Received]) AS DatInt," & _
" format(Month([Date/Time Completed]),'00') & '/' &" & _
" format(Day([Date/Time Completed]),'00') & '/' &" & _
" Year([Date/Time Completed]) AS DatAct, 'PY' AS Bucket," & _
" '9' AS SlType," & _
" '99' AS CDN," & _
" '07' AS SlQues," & _
" '99' AS SlMkt" & _
" FROM " & inTableName & ";"
'Debug.Print strSQL
DoCmd.RunSQL (strSQL)
'Get name of file to export
'This is a fixed-length text file
exportFileName = InputBox("Name of file to export", _
mbTitle, CurDir & "\" & "*.txt"

If exportFileName = "" Then
GoTo Done
End If
'Do the export
DoCmd.TransferText acExportFixed, ExportSpecName, _
outTableName, exportFileName
'Get number of records in outTableName for reporting
'purposes.
'Of course, this assumes that all records got exported
Set rs = db.OpenRecordset(outTableName)
rs.MoveLast
outRecordCount = rs.RecordCount
rs.Close
db.Close
mbRetcode = MsgBox(outRecordCount & _
" records exported to " & vbCrLf & _
exportFileName, vbOKOnly, mbTitle)
Done:
Set rs = Nothing
Set db = Nothing
Exit Sub
ErrHandle:
If Err.Number = 3376 Then
'Table doesn 't exist, caused by drop table, ignore
Debug.Print Err.Number & ": " & Err.Description & vbCrLf
Resume Next
Else
mbRetcode = MsgBox("Error " & Err.Number & vbCrLf & _
Err.Description, vbCritical + vbOKOnly, "Error"
If Err.Number = 3011 Then
'cant find import file - reprompt
Debug.Print Err.Number & ": " & Err.Description & vbCrLf
Resume GetImportName
End If
End If
'Any other errors, cleanup and exit
Resume Done
End Sub