app.path i dunno whats wrong HELP newbie here?

M

macken09

AM USING THIS for
now----------------------------------------------------------------------------------------
Public Sub OpenDBConnection()
Set conn = New ADODB.Connection
Set rec = New ADODB.Recordset
strconek = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Program
Files\balik sa dati\data\MFMS.mdb;Persist Security Info=False"
conn.CursorLocation = adUseClient
conn.Open strconek
End Sub
----------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------
ICANT USE THIS
Public Sub OpenDBConnection()
Set conn = New ADODB.Connection
Set rec = New ADODB.Recordset
strconek = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &
app.path & "\data\MFMS.mdb;Persist Security Info=False"
conn.CursorLocation = adUseClient
conn.Open strconek
End Sub
 
D

Douglas J. Steele

If you're trying to use this from within Access, there is no App object in
Access, so App.Path will (naturally) fail.

Assuming you're using Access 2000 or newer, use CurrentApplication.Path
instead.

BTW, note that both App.Path and CurrentApplication.Path have an annoying
little "feature". If the file is in the root of a drive, what's returned
will have a terminating slash: E:\, not simply E:. That means that something
like

strconek = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &
App.Path & "\data\MFMS.mdb;Persist Security Info=False"

or

strconek = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &
CurrentApplication.Path & "\data\MFMS.mdb;Persist Security Info=False"

will fail, as you'll end up with two slashes in a row.

To get around this, try:

Dim strPath As String

strPath = CurrentApplication.Path
If Right$(strPath, 1) <> "\" Then
strPath = strPath & "\"
End If
strconek = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &
strPath & "\data\MFMS.mdb;Persist Security Info=False"
 
D

Douglas J. Steele

Dirk Goldgar said:
CurrentProject.Path, I think Doug means.

Thanks, Dirk. I've only got Access 97 installed on this machine, so I was
going from memory.

For the record, in Access 97 or earlier, you'd use

Left$(CurrentDb.Name, Len(CurrentDb.Name) - Len(Dir$(CurrentDb.Name)))
 

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