Import problem

O

OnMyOwn

The people I worked with are not skilled enough to import new data into their
databases (they all have a database stored on their hard drives). So I have
created a macro that uses "Transfer Spreadsheet" to import an excel file. Of
course, the location and name of the file is specified in the macro. I
email the excel file to the user and tell them precisely where to save the
attachment (and the name it must be called) before they can run the macro. I
have also instructed them NOT to open the attachment because I don't want the
date and number formats to change. The user tells me that the macro quits or
freezes. They insist that they have saved the file where I told them to.
Does anybody know of a reason why this might happen? Is the user just not
saving it where I told them to? They are using Windows XP. Some of them
might be logging in to a remote server which I know nothing about - could
there be TWO C:\ drives?
 
T

The Wheel Group

Unbelievable..

Sounds like its time for a training session. The problem with "freezing"
may be attributed to an antivirus program or permissions set elsewhere.

Lets see the macro, and btw what is the OS?
 
V

Van T. Dinh

There can only be *one* C: drive. The C: drive on the server will be
qualified with the server name. Also, for most properly configured server,
users don't get access to the server C: drive, only the shares that are set
by the Administrator.

If the user has remote access that shows the Desktop (rarely except for
Administrator), then the server's C: drive is the local C: drive and his/her
work-station's C: drive will be qualified with the work-station name.
 
P

Pieter Wijnen

why not use common dialogs & actually make them select the file to import?

Pieter
 
O

OnMyOwn

LOL! They are still having trouble figuring out how to open their database.
I seriously doubt that they are capable of selecting the file to import.
They wouldn't even know what "import" means.
 
O

OnMyOwn

The operating system is Windows XP.
Macro starts with "TransferSpreadsheet" with the following arguments:
Transfer Type: Import
Spreadsheet Type: Microsoft Excel 8-10
Table Name: Completed Transaction Updated
File name: c:\Scorecard Data\Completed Transaction Updated.xls
Has Field Names: Yes

Macro ends by running an append query to add the record from the spreadsheet
into the table. According to these users, the macro never gets as far as the
append query. When I gave them this macro, I walked them through creating
the folder "Scorecard Data" on their C:\ drive. They insist that is where
they are saving the file and that they are naming it correctly.
 
O

OnMyOwn

Yes, the users can see what they call a "remote desktop". I do not know
where they are keeping their database file. If the database is on the remote
server, then it would probably look at the servers c:\ right? Perhaps this
is the problem.

adr
 
V

Van T. Dinh

If the user uses Remote Desktop to the server, the C: driver in the context
of the Remote Desktop session will be the server C: drive.

I have never heard of a database application where each user has his / her
separate copy of the database!
 
P

Pieter Wijnen

What I meant was offcourse to implement Common Dialog Open File & handle it
from there via Code
I See from the rest of the thread that they use TS & if that is setup with a
local C drive you *do* have serious problems accessing their local C
drives...
Anyways I strongly reccommend to rewrite your macro to VBA code (the only
macro I *allow* is the autokeys macro - as that is the only way to trap
"special" keys globally & that I even redirect to function calls)

HTH

Pieter

PS
The code to implement FileOpen Dialog is to be found at
http://www.mvps.org/Access in the API Section..
 
O

OnMyOwn

Oh. I'm sorry I didn't understand. I don't know any visual basic. I'm just
a secretary.
 
P

Pieter Wijnen

OK - Make a new Module and Paste this code:

'------------------- Code Start ---------------
Option Compare Database
Option Explicit


'File Handling
Private Const FILE_CURRENT = 1
Private Const FILE_BEGIN = 0
Private Const GENERIC_READ = &H80000000
Private Const GENERIC_WRITE = &H40000000
Private Const FILE_SHARE_READ = &H1
Private Const FILE_SHARE_WRITE = &H2
Private Const OPEN_EXISTING = 3
Private Const FILE_FLAG_RANDOM_ACCESS = &H10000000
Private Const FILE_ATTRIBUTE_NORMAL = &H80
Private Const FILE_ATTRIBUTE_ARCHIVE = &H20
Private Const FILE_ATTRIBUTE_DIRECTORY = &H10
Private Const FILE_ATTRIBUTE_HIDDEN = &H2
Private Const FILE_ATTRIBUTE_READONLY = &H1
Private Const FILE_ATTRIBUTE_SYSTEM = &H4
Private Const FILE_ATTRIBUTE_TEMPORARY = &H100
Private Const CREATE_ALWAYS = 2
Private Const BIF_RETURNONLYFSDIRS = 1
Private Const BIF_DONTGOBELOWDOMAIN = 2
Private Const MAX_PATH = 260
Private Const OFN_READONLY = &H1
Private Const OFN_OVERWRITEPROMPT = &H2
Private Const OFN_HIDEREADONLY = &H4
Private Const OFN_NOCHANGEDIR = &H8
Private Const OFN_SHOWHELP = &H10
Private Const OFN_ENABLEHOOK = &H20
Private Const OFN_ENABLETEMPLATE = &H40
Private Const OFN_ENABLETEMPLATEHANDLE = &H80
Private Const OFN_NOVALIDATE = &H100
Private Const OFN_ALLOWMULTISELECT = &H200
Private Const OFN_EXTENSIONDIFFERENT = &H400
Private Const OFN_PATHMUSTEXIST = &H800
Private Const OFN_FILEMUSTEXIST = &H1000
Private Const OFN_CREATEPROMPT = &H2000
Private Const OFN_SHAREAWARE = &H4000
Private Const OFN_NOREADONLYRETURN = &H8000
Private Const OFN_NOTESTFILECREATE = &H10000
Private Const OFN_NONETWORKBUTTON = &H20000
Private Const OFN_NOLONGNAMES = &H40000 ' force no
long Names for 4.x modules
Private Const OFN_EXPLORER = &H80000 ' new look
commdlg
Private Const OFN_NODEREFERENCELINKS = &H100000
Private Const OFN_LONGNAMES = &H200000 ' force long
Names for 3.x modules
Private Const OFN_SHAREFALLTHROUGH = 2
Private Const OFN_SHARENOWARN = 1
Private Const OFN_SHAREWARN = 0
Private Const MAXDWORD = &HFFFF
Private Const INVALID_HANDLE_VALUE = -1
Private Type OpenFilename
lStructSize As Long
hwndOwner As Long
hInstance As Long
lpstrFilter As String
lpstrCustomFilter As String
nMaxCustFilter As Long
nFilterIndex As Long
lpstrFile As String
nMaxFile As Long
lpstrFileTitle As String
nMaxFileTitle As Long
lpstrInitialDir As String
lpstrTitle As String
flags As Long
nFileOffset As Integer
nFileExtension As Integer
lpstrDefExt As String
lCustData As Long
lpfnHook As Long
lpTemplateName As String
End Type
Declare Function GetFocus Lib "User32" () As Long
Private Declare Function GetOpenFileName Lib "comdlg32.dll" Alias
"GetOpenFileNameA" (pOpenfilename As OpenFilename) As Long

Function vbString(ByVal CString As String) As String
On Error Resume Next
Dim Pos As Long
Pos = VBA.InStr(CString, vbNullChar)
If Pos Then
vbString = VBA.Left(CString, Pos - 1)
Else
vbString = CString
End If
End Function
Function CString(Optional ByVal MaxLen As Long = 255) As String
On Error Resume Next
CString = VBA.String(MaxLen, 0)
End Function

Public Function GetFileName(Optional ByVal Title As String = "Locate File",
Optional ByVal Filter As String = "All Files (*.*)|*.*|", Optional ByVal
InitFile As String = VBA.vbNullString) As String
Dim OpenFile As OpenFilename
Dim Res As Long
Dim sFilter As String
Dim Pos As Integer, i As Integer
sFilter = " " & Filter & " "
Pos = VBA.InStr(sFilter, "|")
If Pos = 0 Then
sFilter = " All Files (*.*)|*.*| "
Pos = VBA.InStr(sFilter, "|")
End If
While Pos > 0
sFilter = VBA.Left(sFilter, Pos - 1) & VBA.vbNullChar &
VBA.Mid(sFilter, Pos + 1)
Pos = VBA.InStr(sFilter, "|")
Wend
sFilter = VBA.Trim(sFilter)
With OpenFile
.lStructSize = Len(OpenFile)
.hwndOwner = GetFocus()
.hInstance = 0
.lpstrFile = InitFile & String(257 - VBA.Len(InitFile), 0)
If Len(InitFile) = 0 Then
.lpstrInitialDir = VBA.CurDir()
ElseIf VBA.Len(VBA.Dir(InitFile)) = 0 Then
.lpstrInitialDir = VBA.CurDir()
' ElseIf vba.instr(InitFile, "*") Then
' .lpstrInitialDir = vba.left(InitFile, vba.instr(InitFile, "*") - 1)
' .lpstrFile = vba.Mid(InitFile, vba.instr(InitFile, "*"))
' .lpstrFile = .lpstrFile & String(257 - len(.lpstrFile), 0)
Else
.lpstrInitialDir = VBA.Left(InitFile, VBA.InStr(1, InitFile,
VBA.Dir(InitFile), 1) - 1)
.lpstrFile = VBA.Dir(InitFile) & VBA.String(257 -
VBA.Len(VBA.Dir(InitFile)), 0)
End If
.lpstrFilter = sFilter
.nFilterIndex = 1
.nMaxFile = Len(.lpstrFile) - 1
.lpstrFileTitle = .lpstrFile
.nMaxFileTitle = .nMaxFile
.lpstrTitle = Title
.flags = OFN_SHARENOWARN Or OFN_EXPLORER Or OFN_READONLY Or
OFN_HIDEREADONLY Or OFN_FILEMUSTEXIST Or OFN_PATHMUSTEXIST
End With
Res = GetOpenFileName(OpenFile)
If Res <> 0 Then
With OpenFile
GetFileName = vbString(.lpstrFile)
End With
End If
End Function

Function ImportExcel(ByVal TableName As String) As boolean
On Error Resume Next
Dim FileName As String
FileName = GetFileName("Please Select File", "Excel Workbook
(*.xl?)|*.xl?")
If Len(FileName) Then
Access.DoCmd.TransferSpreadsheet acImport, , TableName, FileName
End If

End Function

'------------------- Code End ----------------

modify the macro you're using to:
Action: Runcode
Function Name: ImportExcel("TheTableToImport")

HTH

Pieter
 
Top