how do I get the database directory name from a server?

G

Guest

I have a workorder database resident on a server, with many users, who do
not necessarily have the same drive mappings . My problem is that I need to
import the contents of a text file into a text field on my form. I've scanned
most of the forums, and have come up with some code to do this, but
.......it's not working...keep in mind that I am definitely NOT a programmer
in VB.
Here is the code I'm working with


Function CurrentDBDir() As String
Dim strDBPath As String
Dim strDBFile As String
strDBPath = CurrentDb.Name
strDBFile = Dir(strDBPath)
CurrentDBDir = Left$(strDBPath, Len(strDBPath) - Len(strDBFile))
End Function

Private Sub ActivityCode_Exit(Cancel As Integer)
If Me.ActivityCode.Value = "H40" Then
Dim strFileSpec As String
strFileSpec = "c:\maint\rb211post.txt"

((((need to replace 'c:\maint' with the result of determining the actual
directory where the database resides))))) If I substitute c:\maint with
CurrentDBDir I get an error on the next statement. otherwise the private sub
activity code works, cuz my test database is local to my hard drive.

Me.problem.Value = FileContents(strFileSpec, True)
End If

End Sub
 
J

John Nurick

Hi Russ,

If you're using a recent version of Access, just use
CurrentProject.Path
Otherwise, have you tested your CurrentDBDir() function to make sure
it's working as you expect?

After that, it's just a matter of
strFileSpec = CurrentProject.Path & "\" & "rb211post.txt"
 
G

Guest

John Nurick said:
Hi Russ,

If you're using a recent version of Access, just use
CurrentProject.Path
Otherwise, have you tested your CurrentDBDir() function to make sure
it's working as you expect?

After that, it's just a matter of
strFileSpec = CurrentProject.Path & "\" & "rb211post.txt"


thanks for the quick response...
I'm using Access 2002, and shortly upgrading to 2003.
I'm also assuming that I won't need 'Function CurrentDBDir() As String'
anymore.
Again thanks a mil.........
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top