Link to home
Start Free TrialLog in
Avatar of robsking
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:\masterdatabase.mdb")
Set rst = dbCheck.OpenRecordset("SELECT tblMasterUser.Path FROM tblMasterUser WHERE ((tblMasterUser.District_Manager) = 'Joe Smith')")


On Error Resume Next
 DownloadFile "X:\Database.mde", " & rst("Path") & "Database.mde"
Set rst = Nothing
Set dbCheck = Nothing

End Function
Avatar of RDWaibel
RDWaibel
Flag of United States of America image

the .path could be an issue.
am I assuming correctly then this is the line that is failing?
{Set rst = dbCheck.OpenRecordset("SELECT tblMasterUser.Path FROM tblMasterUser WHERE ((tblMasterUser.District_Manager) = 'Joe Smith')")}

you may need to change the field name to UserPath
Avatar of robsking
robsking

ASKER

Is Path a reserved word?
yes, in VB.  as VBA is a 'type' or subset of VB.  this could be the whole issue.
Just changed it to userpath. It's not the problem.
what line is failing, the select statement?
This line is in red.

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
in the immediate window, type

?rst("UserPath")

press enter and tell me what is says.
compile error sub or function not defined
what form does Path take??

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").Value & "\Database.mde"

Steve
try rst!path
Yes. Path = c:\
or c:\windows\desktop
what does "DownloadFile" do?
ASKER CERTIFIED SOLUTION
Avatar of stevbe
stevbe

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
Steve,
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
Thanks guys!
I take it you fixed it?
Yes. I played with the Windows API a bit. Thanks
very good!