robsking
asked on
Funtion to download file while referencing path located in database field.
The path to the users folder is located in the masterdatabase. The error is on the word named path. Any solutions? Thanks
Public Function basImportDatabase()
Dim dbCheck As DAO.Database
Dim rst As DAO.Recordset
Set dbCheck = DBEngine.OpenDatabase("X:\ masterdata base.mdb")
Set rst = dbCheck.OpenRecordset("SEL ECT tblMasterUser.Path FROM tblMasterUser WHERE ((tblMasterUser.District_M anager) = 'Joe Smith')")
On Error Resume Next
DownloadFile "X:\Database.mde", " & rst("Path") & "Database.mde"
Set rst = Nothing
Set dbCheck = Nothing
End Function
Public Function basImportDatabase()
Dim dbCheck As DAO.Database
Dim rst As DAO.Recordset
Set dbCheck = DBEngine.OpenDatabase("X:\
Set rst = dbCheck.OpenRecordset("SEL
On Error Resume Next
DownloadFile "X:\Database.mde", " & rst("Path") & "Database.mde"
Set rst = Nothing
Set dbCheck = Nothing
End Function
ASKER
Is Path a reserved word?
yes, in VB. as VBA is a 'type' or subset of VB. this could be the whole issue.
ASKER
Just changed it to userpath. It's not the problem.
what line is failing, the select statement?
ASKER
This line is in red.
DownloadFile "X:\Database.mde", " & rst("UserPath") & "Database.mde"
DownloadFile "X:\Database.mde", " & rst("UserPath") & "Database.mde"
have you debugged the return from rst("Path") ?
using On Erro Resume next will make this difficult ... can you tell us what the specific error is?
MsgBox rst.Fields("Path").Value
Steve
using On Erro Resume next will make this difficult ... can you tell us what the specific error is?
MsgBox rst.Fields("Path").Value
Steve
in the immediate window, type
?rst("UserPath")
press enter and tell me what is says.
?rst("UserPath")
press enter and tell me what is says.
ASKER
compile error sub or function not defined
what form does Path take??
if path = C:\hi
it will attempt to download c:\hidatabase.mde
if path = C:\hi
it will attempt to download c:\hidatabase.mde
... is the path missing the final back slash ?
DownloadFile "X:\Database.mde", " & rst.Fields("UserPath").Val ue & "\Database.mde"
Steve
DownloadFile "X:\Database.mde", " & rst.Fields("UserPath").Val
Steve
try rst!path
ASKER
Yes. Path = c:\
or c:\windows\desktop
or c:\windows\desktop
what does "DownloadFile" do?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
my code will change
c:\windows\desktop to c:\windows\desktop\ which is the issue ... no trailing backslash
so next question is ... will DownloadFile create the "Path" directory if it does not exist or do you need code to do that before the download?
Steve
c:\windows\desktop to c:\windows\desktop\ which is the issue ... no trailing backslash
so next question is ... will DownloadFile create the "Path" directory if it does not exist or do you need code to do that before the download?
Steve
ASKER
Steve,
This line is red.
DownloadFile "X:\Database.mde", " & rst("Path") & "Database.mde"
This line is red.
DownloadFile "X:\Database.mde", " & rst("Path") & "Database.mde"
what is the signature for DownloadFile ... how many parameters is it expecting? does it build the destination folder if it does not exist? I ask these questions because DownloadFile is not a builtin Access function.
Steve
Steve
ASKER
Thanks guys!
I take it you fixed it?
ASKER
Yes. I played with the Windows API a bit. Thanks
very good!
am I assuming correctly then this is the line that is failing?
{Set rst = dbCheck.OpenRecordset("SEL
you may need to change the field name to UserPath