Hi All,
I have a MS Access application and the users are supposed to export and Import files using this application. This application would be located on network. The path where the files will be exported will always be the same as of the application for e.g
L:9098909802REDSREDSUSERDonor MotivationRecptControltest
Now I can put this path in the code and it runs just fine.
The problem is different users have used different drives to map to this directory.
I tried using genralised path like:
RK8VOL8029098909802REDSREDSUSERDonor MotivationRecptControltest
it does’nt work….
Please suggest some options that I could use…..
![]() |
Patch reliability is unclear. Unless you have an immediate, pressing need to install a specific patch, don't do it. |
SIGN IN | Not a member? | REGISTER | PLUS MEMBERSHIP |
-
Getting the application’s path at network (MS Access 97)
Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » Getting the application’s path at network (MS Access 97)
- This topic has 9 replies, 5 voices, and was last updated 22 years, 2 months ago.
AuthorTopicWSishasingh
AskWoody LoungerNovember 29, 2002 at 4:22 pm #380127Viewing 0 reply threadsAuthorReplies-
WSishasingh
AskWoody LoungerNovember 29, 2002 at 5:00 pm #635439I realised all I want to solve this problem is the application path.
Here is the code that I used to get the path of the mdb:Public Function GetAPath()
Dim FullPath$, AppPath$
Dim DB As Database
Dim iloc As Integer
Dim X As IntegerSet DB = CurrentDb
FullPath = DB.Name
For X = Len(FullPath) To 1 Step -1
iloc = InStr(X, FullPath, “”)
If iloc 0 Then
Exit For
End If
Next XGetAPath = Mid$(FullPath, 1, iloc)
End Function
And then I am calling this function from the following :
Private Sub exportFile(qryName As String)
DoCmd.TransferSpreadsheet acExport, 8, qryName, GetAPath + qryName, True, “”
End Sub -
WSjohnhutchison
AskWoody LoungerNovember 30, 2002 at 1:31 am #635536Here is slightly simpler version of your function:
Public Function fngetpath() As String
Dim mypath As String
Dim myfilename As String
mypath = CurrentDb().Name
myfilename = Dir(mypath)
mypath = Left(mypath, Len(mypath) – Len(myfilename))
End FunctionOne proviso
If you have a db split into be/fe, with the fe on the local machine, this function and yours will both return the location of the fe not the be. Instead in that case you need the location of the back end.
This function will do that:public function fnGetnetworkPath() as string Dim db As Database Set db = CurrentDb Dim strpath As String Dim lnglength As Long Dim tabledef As TableDef Dim strconnect As String Set tabledef = db.TableDefs("tblPatients") strconnect = mytabledef.Connect ' msgbox(myconnect) lnglength = Len(strconnect) strpath = Right(strconnect, lnglength - 10) lnglength = Len(strpath) strpath = Left(strpath, lnglength - 16) fnGetnetworkPath = strpath end function
You would need to change tblPatients to one of your tables.
The connection string includes the path but precedes it by a database type description, and finishes with the full file name. These are removed to leave the path. The 10 and 16 in my code are just hardcoded values for the length of these. -
WSchrisgreaves
AskWoody Lounger -
WSjohnhutchison
AskWoody Lounger -
WSMarkD
AskWoody LoungerMarch 8, 2003 at 1:31 am #659721I don’t know if this is an improvement or not, but it should not be necessary to “hard code” the lengths used in function if you are dealing with a linked .MDB table, which has a “standard” connection string. Sample function to return path of linked .MDB table (assumes linked file is an .MDB file):
Public Function GetLinkedTablePath(ByVal strTbl As String) As String
Dim db As DAO.Database
Dim tbl As DAO.TableDef
Dim strConn As String
Dim strMsg As String
Dim intStart As Integer‘ This function intended for linked .MDB tables only!
‘ TableDef Attributes property:
‘ &H40000000 = Linked ISAM (.mdb, .xls, .txt, etc)
‘ &H20000000 = Linked ODBC
‘ Connection string example:
‘ ;DATABASE=H:09AACCESSFILESNorthwind.mdbSet db = CurrentDb
Set tbl = db.TableDefs(strTbl)
strConn = tbl.Connect‘ Note: This excludes “” at end of path; modify if necessary:
If tbl.Attributes = &H40000000 And Right(strConn, 4) = “.mdb” Then
intStart = 11 ‘ Based on standard conn string for linked .MDB table
GetLinkedTablePath = Mid(strConn, intStart, InStrRev(strConn, “”, -1, 0) – intStart)
Else
strMsg = “Specified Table (” & strTbl & “) is not a linked .MDB table.”
MsgBox strMsg, vbExclamation, “NOT LINKED TABLE”
GetLinkedTablePath = “”
End IfExit_Function:
Set db = Nothing
Set tbl = Nothing
Exit Function
Err_Handler:
strMsg = “Error No ” & Err.Number & “: ” & Err.Description
Beep
MsgBox strMsg, vbExclamation, “ERROR MESSAGE”
Resume Exit_Function
End FunctionExample of use (local hard drive, works same if on network); returns path for standard installation of Northwind.mdb in Access XP/2002:
? GetLinkedTablePath(“Products1”)
C:Program FilesMicrosoft OfficeOffice10SamplesFunction can be modified for use with other linked table types, which have varying connection string formats….
-
WSMarkD
AskWoody LoungerMarch 8, 2003 at 1:32 pm #659758(Edited by MarkD on 08-Mar-03 09:32. Minor clarifications.)
As alternative to DAO TableDef properties, you can use ADOX properties to get path for non-ODBC linked tables. Sample function returns full path of linked table, including or excluding file name of source db, depending on option specified in 2nd argument:
Public Function GetLinkedTablePathADO(strTbl As String, intOpt As Integer) As String
On Error GoTo Err_Handler‘ intOpt = 1: returns source database full path (including filename)
‘ intOpt = 2: returns source database full path (excluding filename)
‘ Linked .TXT file: Use intOpt 1, returns path only
‘ Linked .XLS file: same as .MDB
‘ Does not work with linked ODBC tables
‘ ODBC tables: parse string returned by “JET OLEDB:Link Provider String” propertyDim cat As New ADOX.Catalog
Dim tbl As ADOX.Table
Dim strProp As String
Dim strPath As String
Dim strMsg As Stringcat.ActiveConnection = CurrentProject.Connection
Set tbl = cat.Tables(strTbl)
strProp = “Jet OLEDB:Link Datasource”
strPath = tbl.Properties(strProp).ValueIf Len(strPath) > 0 Then
If intOpt = 2 Then
strPath = Left(strPath, InStrRev(strPath, “”, -1, 0) – 1)
End If
GetLinkedTablePathADO = strPath
Else
strMsg = strTbl & ” is not a valid linked table.”
MsgBox strMsg, vbExclamation, “INVALID TABLE”
GetLinkedTablePathADO = “”
End IfExit_Function:
Set cat = Nothing
Set tbl = Nothing
Exit Function
Err_Handler:
strMsg = “Error No ” & Err.Number & “: ” & Err.Description
MsgBox strMsg, vbExclamation, “ERROR MESSAGE”
Resume Exit_FunctionEnd Function
Example of use:
? GetLinkedTablePathADO(“Products1”,1)
C:Program FilesMicrosoft OfficeOffice10SamplesNorthwind.mdb? GetLinkedTablePathADO(“Products1”,2)
C:Program FilesMicrosoft OfficeOffice10SamplesThis may be simpler than DAO appoach in previous example? Only drawback, I don’t see simple way to distinguish linked ISAM from linked ODBC tables the way you can with DAO TableDef Attributes property, other than to test for Link Datasource property returning an empty string. Also, when testing both methods, the DAO method was VERY slow, taking several seconds to return connection string (even on local drive), whereas the ADOX function returned string with no delay. You’d have to test both to see if this applies on your system. To use this example, set a reference to Microsoft ADO Ext. 2.x for DDL and Security (ADOX) type library (MSADOX.DLL).
HTH
-
WScharlotte
AskWoody LoungerMarch 8, 2003 at 2:31 pm #659777The worst thing about working with ADO for this is that the OLEDB properties have such clunky names. There are no simple property names like “Connect” or “SourceTable”. Instead, you have to get the OLEDB property name exactly right for the correct provider and they can be pretty much whatever the provider decides to call them. That provides tremendous flexibility in developing OLEDB drivers but it can be awfully frustrating for the developer using them.
Once you’ve build the code, it runs nicely, of course.
-
WSMarkD
AskWoody LoungerMarch 8, 2003 at 3:49 pm #659792You’re right about the clunky property names. I had to loop thru table properties to get right syntax using sub like this:
Public Sub GetADOTableProperties(strTbl As String)
On Error Resume NextDim cat As New ADOX.Catalog
Dim tbl As ADOX.Table
Dim i As Integercat.ActiveConnection = CurrentProject.Connection
Set tbl = cat.Tables(strTbl)For i = 1 To tbl.Properties.Count – 1
Debug.Print tbl.Properties(i).Name & “: ” & tbl.Properties(i).Value
Next iSet cat = Nothing
Set tbl = NothingEnd Sub
Example (linked .MDB table):
GetADOTableProperties(“Products1”)
Jet OLEDB:Table Validation Text:
Jet OLEDB:Table Validation Rule:
Jet OLEDB:Cache Link Name/Password: False
Jet OLEDB:Remote Table Name: Products
Jet OLEDB:Link Provider String:
Jet OLEDB:Link Datasource: C:Program FilesMicrosoft OfficeOffice10SamplesNorthwind.mdb
Jet OLEDB:Exclusive Link: False
Jet OLEDB:Create Link: True
Jet OLEDB:Table Hidden In Access: FalseLike that last property listed; I think a simple “Hidden” may have sufficed as property name….
-
WScharlotte
AskWoody LoungerMarch 8, 2003 at 5:16 pm #659801Yes, everyone working with ADO needs a routine like this in their toolkit because every provider’s properties are different. So is you change the provider to SQL Server, you’ve got a whole new set of properties to work with.
That means, you have to enum the property names for each provider before you start working with them.
-
-
-
-
Viewing 0 reply threads -

Plus Membership
Donations from Plus members keep this site going. You can identify the people who support AskWoody by the Plus badge on their avatars.
AskWoody Plus members not only get access to all of the contents of this site -- including Susan Bradley's frequently updated Patch Watch listing -- they also receive weekly AskWoody Plus Newsletters (formerly Windows Secrets Newsletter) and AskWoody Plus Alerts, emails when there are important breaking developments.
Get Plus!
Welcome to our unique respite from the madness.
It's easy to post questions about Windows 11, Windows 10, Win8.1, Win7, Surface, Office, or browse through our Forums. Post anonymously or register for greater privileges. Keep it civil, please: Decorous Lounge rules strictly enforced. Questions? Contact Customer Support.
Search Newsletters
Search Forums
View the Forum
Search for Topics
Recent Topics
-
A CVE-MITRE-CISA-CNA Extravaganza
by
Nibbled To Death By Ducks
5 hours, 1 minute ago -
Sometimes I wonder about these bots
by
Susan Bradley
1 hour, 19 minutes ago -
Does windows update component store “self heal”?
by
Mike Cross
17 hours, 58 minutes ago -
Windows 11 Insider Preview build 27858 released to Canary
by
joep517
18 hours, 59 minutes ago -
Pwn2Own Berlin 2025: Day One Results
by
Alex5723
18 hours, 24 minutes ago -
Windows 10 might repeatedly display the BitLocker recovery screen at startup
by
Susan Bradley
14 hours, 54 minutes ago -
Windows 11 Insider Preview Build 22631.5409 (23H2) released to Release Preview
by
joep517
21 hours, 40 minutes ago -
Windows 10 Build 19045.5912 (22H2) to Release Preview Channel
by
joep517
21 hours, 42 minutes ago -
Kevin Beaumont on Microsoft Recall
by
Susan Bradley
10 hours, 16 minutes ago -
The Surface Laptop Studio 2 is no longer being manufactured
by
Alex5723
1 day, 5 hours ago -
0Patch, where to begin
by
cassel23
23 hours, 51 minutes ago -
CFPB Quietly Kills Rule to Shield Americans From Data Brokers
by
Alex5723
1 day, 19 hours ago -
89 million Steam account details just got leaked,
by
Alex5723
1 day, 7 hours ago -
KB5058405: Linux – Windows dual boot SBAT bug, resolved with May 2025 update
by
Alex5723
2 days, 4 hours ago -
A Validation (were one needed) of Prudent Patching
by
Nibbled To Death By Ducks
1 day, 18 hours ago -
Master Patch Listing for May 13, 2025
by
Susan Bradley
1 day, 6 hours ago -
Installer program can’t read my registry
by
Peobody
3 hours, 4 minutes ago -
How to keep Outlook (new) in off position for Windows 11
by
EspressoWillie
1 day, 16 hours ago -
Intel : CVE-2024-45332, CVE-2024-43420, CVE-2025-20623
by
Alex5723
2 days ago -
False error message from eMClient
by
WSSebastian42
2 days, 15 hours ago -
Awoke to a rebooted Mac (crashed?)
by
rebop2020
3 days ago -
Office 2021 Perpetual for Mac
by
rebop2020
3 days, 1 hour ago -
AutoSave is for Microsoft, not for you
by
Will Fastie
4 hours ago -
Difface : Reconstruction of 3D Human Facial Images from DNA Sequence
by
Alex5723
3 days, 4 hours ago -
Seven things we learned from WhatsApp vs. NSO Group spyware lawsuit
by
Alex5723
12 hours, 22 minutes ago -
Outdated Laptop
by
jdamkeene
3 days, 10 hours ago -
Updating Keepass2Android
by
CBFPD-Chief115
3 days, 15 hours ago -
Another big Microsoft layoff
by
Charlie
3 days, 15 hours ago -
PowerShell to detect NPU – Testers Needed
by
RetiredGeek
17 hours, 35 minutes ago -
May 2025 updates are out
by
Susan Bradley
50 minutes ago
Recent blog posts
Key Links
Want to Advertise in the free newsletter? How about a gift subscription in honor of a birthday? Send an email to sb@askwoody.com to ask how.
Mastodon profile for DefConPatch
Mastodon profile for AskWoody
Home • About • FAQ • Posts & Privacy • Forums • My Account
Register • Free Newsletter • Plus Membership • Gift Certificates • MS-DEFCON Alerts
Copyright ©2004-2025 by AskWoody Tech LLC. All Rights Reserved.