vba - retrieve current path from file saved on server -


how can retrieve current path of current db? i've 1 ac07 program, distribute save 1 copy on intranet server, how copy program our pc , use it? people open file directly on server.

when file open 1 form star automatically, in form put code:

 private sub form_load() on error goto errorhandler dim strserver string strserver = "\\itbgafs01\comune\dashboard\" if getdbpath() = strserver     msgbox "you can't open file server" & vbcrlf & _             "save 1 copy on pc, , use those", vbcritical, "dashboard.info"     application.quit end if public function getdbpath() string     dim strfullpath string     dim integer      strfullpath = currentdb().name      = len(strfullpath) 1 step -1         if mid(strfullpath, i, 1) = "\"             getdbpath = left(strfullpath, i)             exit         end if     next end function 

my problem is: pc mapped on drive h: server directory path result h:\comune\dashboard\ , not \\itbgafs01\\dashboard\. how can retrieve absolute path? first think use more if like:

 private sub form_load() on error goto errorhandler dim strserver string dim strmaph string strserver = "\\itbgafs01\comune\dashboard\" strmaph = "h:\comune\dashboard\" msgbox strserver & vbcrlf & _         strmaph & vbcrlf & _         getdbpath() if getdbpath() = strserver or getdbpath() = strmaph     msgbox "non puoi aprire il file sul server" & vbcrlf & _             "copialo sul tuo pc ed avvia il programma da li", vbcritical, "dashboard.info"     application.quit end if 

is there way it?

you can use scripting runtime unc path of drive replace in currentdb.name.

e.g.:

sub blah()     debug.print getuncpath(currentdb.name) end sub   function getuncpath(path string) string     dim fso object, sharename     set fso = createobject("scripting.filesystemobject")      sharename = fso.getdrive( _                             fso.getdrivename(path)).sharename      'sharename empty if wasn't network mapped drive (e.g. local c: drive)     if sharename <> ""         getuncpath = sharename & right(path, len(path) - instr(1, path, "\"))     else         getuncpath = path     end if  end function 

edit: alternatively can use call winapi info: https://support.microsoft.com/en-us/kb/160529


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -

jdbc - Not able to establish database connection in eclipse -