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, 3 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
-
EchoLeak : Zero Click M365 Copilot leak sensitive information
by
Alex5723
12 minutes ago -
24H2 may not be offered June updates
by
Susan Bradley
22 minutes ago -
Acronis : Tracking Chaos RAT’s evolution (Windows, Linux)
by
Alex5723
12 hours, 46 minutes ago -
Turning off OneDrive
by
CWBillow
17 hours, 15 minutes ago -
June 2025 updates are out
by
Susan Bradley
2 hours, 45 minutes ago -
Mozilla shutting Deep Fake Detector
by
Alex5723
1 day, 3 hours ago -
Windows-Maintenance-Tool (.bat)
by
Alex5723
12 hours, 55 minutes ago -
Windows 11 Insider Preview build 26200.5641 released to DEV
by
joep517
1 day, 6 hours ago -
Windows 11 Insider Preview build 26120.4250 (24H2) released to BETA
by
joep517
1 day, 6 hours ago -
Install Office 365 Outlook classic on new Win11 machine
by
WSrcull999
1 day, 6 hours ago -
win 10 to win 11 with cpu/mb replacement
by
aquatarkus
21 hours, 57 minutes ago -
re-install Windows Security
by
CWBillow
1 day, 9 hours ago -
WWDC 2025 Recap: All of Apple’s NEW Features in 10 Minutes!
by
Alex5723
1 day, 13 hours ago -
macOS Tahoe 26
by
Alex5723
1 day, 7 hours ago -
Migrating from win10 to win11, instructions coming?
by
astro46
19 minutes ago -
Device Eligibility for Apple 2026 Operating Systems due this Fall
by
PKCano
21 hours, 48 minutes ago -
Recommended watching : Mountainhead movie
by
Alex5723
22 hours, 32 minutes ago -
End of support for Windows 10
by
Old enough to know better
6 hours, 3 minutes ago -
What goes on inside an LLM
by
Michael Covington
16 hours, 41 minutes ago -
The risk of remote access
by
Susan Bradley
2 hours, 58 minutes ago -
The cruelest month for many Office users
by
Peter Deegan
32 minutes ago -
Tracking protection and trade-offs in Edge
by
Mary Branscombe
1 day, 2 hours ago -
Supreme Court grants DOGE access to confidential Social Security records
by
Alex5723
2 days, 11 hours ago -
EaseUS Partition Master free 19.6
by
Alex5723
1 day, 12 hours ago -
Microsoft : Edge is better than Chrome
by
Alex5723
3 days ago -
The EU launched DNS4EU
by
Alex5723
3 days, 13 hours ago -
Cell Phone vs. Traditional Touchtone Phone over POTS
by
280park
3 days, 3 hours ago -
Lost access to all my networked drives (shares) listed in My Computer
by
lwerman
3 days, 18 hours ago -
Set default size for pasted photo to word
by
Cyn
4 days ago -
Dedoimedo tries 24H2…
by
Cybertooth
3 days, 12 hours 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.