S
SusanV
Hi all,
I have 2 pieces of code to import data (posted below). The string variable
strFile gives me the entire path where the imported files reside with the
filename. This works beautifully using TransferSpreadsheet, but not with the
TransferDatabase - it seems to want the path separate from the filename. To
be a bit more clear, if I hardcode the path and filename like this it works
fine:
DoCmd.TransferDatabase acImport, "DBase III", "C:\TEST\", acTable, _
"GenericPlans.dbf", "tblPMOPlans"
The error I get when using the strFile variable as shown in the PLANS: code
below is "C:\Temp\GenericPlans.dbf is not a valid path."
How can I grab the info from the user input for this? It works wonderfully
with Transfer Spreadsheet and I just can't seem to get this right for
TransferDatabase. I have to have the flexibility, as I know I can't count on
users to always save the dbf in the same place - they receive it via email -
and I also have no control over the filename, but know it will always be
DBase III.
Perhaps some sort of String manipulation to break apart the path and
filename?
Thanks to any and all, code below,
SusanV
''' code start ''''
PUMPS:
MsgBox "Select the file containing the data for the " & tblName
strFile = ahtCommonFileOpenSave(Filter:=strFilter, OpenFile:=True, _
DialogTitle:="Select Excel file for PUMPS")
If strFile = "" Then
MsgBox "User Cancelled Operation"
Exit Function
End If
'If table exists, delete before proceeding
If Not IsNull(DLookup("[Name]", "MSysObjects", "[Name] = 'tblTemp'"))
Then
DoCmd.DeleteObject acTable, "tblTemp"
End If
DoCmd.TransferSpreadsheet acImport, , "tblTemp", strFile, True
PLANS:
msg = "Do you have a new dbf file for PMO Generic Plans to import?"
rsp = MsgBox(msg, vbYesNo, "New Plan DBF?")
If rsp = vbYes Then
MsgBox "Select the DBF file containing the new Generic Plan data."
strFile = ahtCommonFileOpenSave(Filter:=strFilter, OpenFile:=True, _
DialogTitle:="Select new PMO Plan DBF file ")
If strFile = "" Then
MsgBox "User Cancelled Operation"
Exit Function
End If
'If exists, delete before proceeding
If Not IsNull(DLookup("[Name]", "MSysObjects", "[Name] = 'tblPMOPlans'"))
Then
DoCmd.DeleteObject acTable, "tblPMOPlans"
End If
DoCmd.TransferDatabase acImport, "DBase III", strFile, acTable, _
strFile, "tblPMOPlans"
''' code end ''''
I have 2 pieces of code to import data (posted below). The string variable
strFile gives me the entire path where the imported files reside with the
filename. This works beautifully using TransferSpreadsheet, but not with the
TransferDatabase - it seems to want the path separate from the filename. To
be a bit more clear, if I hardcode the path and filename like this it works
fine:
DoCmd.TransferDatabase acImport, "DBase III", "C:\TEST\", acTable, _
"GenericPlans.dbf", "tblPMOPlans"
The error I get when using the strFile variable as shown in the PLANS: code
below is "C:\Temp\GenericPlans.dbf is not a valid path."
How can I grab the info from the user input for this? It works wonderfully
with Transfer Spreadsheet and I just can't seem to get this right for
TransferDatabase. I have to have the flexibility, as I know I can't count on
users to always save the dbf in the same place - they receive it via email -
and I also have no control over the filename, but know it will always be
DBase III.
Perhaps some sort of String manipulation to break apart the path and
filename?
Thanks to any and all, code below,
SusanV
''' code start ''''
PUMPS:
MsgBox "Select the file containing the data for the " & tblName
strFile = ahtCommonFileOpenSave(Filter:=strFilter, OpenFile:=True, _
DialogTitle:="Select Excel file for PUMPS")
If strFile = "" Then
MsgBox "User Cancelled Operation"
Exit Function
End If
'If table exists, delete before proceeding
If Not IsNull(DLookup("[Name]", "MSysObjects", "[Name] = 'tblTemp'"))
Then
DoCmd.DeleteObject acTable, "tblTemp"
End If
DoCmd.TransferSpreadsheet acImport, , "tblTemp", strFile, True
PLANS:
msg = "Do you have a new dbf file for PMO Generic Plans to import?"
rsp = MsgBox(msg, vbYesNo, "New Plan DBF?")
If rsp = vbYes Then
MsgBox "Select the DBF file containing the new Generic Plan data."
strFile = ahtCommonFileOpenSave(Filter:=strFilter, OpenFile:=True, _
DialogTitle:="Select new PMO Plan DBF file ")
If strFile = "" Then
MsgBox "User Cancelled Operation"
Exit Function
End If
'If exists, delete before proceeding
If Not IsNull(DLookup("[Name]", "MSysObjects", "[Name] = 'tblPMOPlans'"))
Then
DoCmd.DeleteObject acTable, "tblPMOPlans"
End If
DoCmd.TransferDatabase acImport, "DBase III", strFile, acTable, _
strFile, "tblPMOPlans"
''' code end ''''