Currentdb.Name Function

RobH

New member
Local time
Today, 00:25
Joined
Aug 15, 2007
Messages
2
Hi

I using the CurrentDB.Name function to check the filepath of a database to make sure that the users are using the network version (a problem caused by the previous developer meant that some users were working off standalone copies of the db rather than the network copy!!). This seems to be working for all users except one. She is definately opening the network version (I can see the changes she has made) but the Currentdb.Name statement is returning a different filepath.

True file path: "N:\TrustCancelledOps\Cancel2001.mdb"
CurrentDB.Name returns: "N:\TrustC~1\Cancel2001.mdb"

Does anyone know why this is happening or how I can workaround it? Thanks in advance.

Code (in Form_Open event of Form which runs off autoexec):

Dim strFilePath As String
strFilePath = CurrentDb.Name

If strFilePath Like "N:\TrustCancelledOps\Cancel2001.mdb" Then
Exit Sub 'if correct path/filename then no action needed
Else
MsgBox "The database is in the filepath " & strFilePath & " and is therefore not the live database. " & vbCrLf & _
"Please exit the database and contact the database administrator on 66477 for access to the correct database.", vbCritical, "Warning: Invalid Database File."

Cancel = True 'don't open this form (which tells them they are in live database) as they are not in live database

End If
 
What you are getting is the shortened path to your DB to comply with the old DOS naming standard(8 char file name with 3 char extension). It will actually work (surpringly enough!) and take you to the correct place.

Just amend your if line of code to read

If strFilePath Like "N:\TrustCancelledOps\Cancel2001.mdb" Or strFilePath like "N:\TrustC~1\Cancel2001.mdb" Then

and everything should work OK.

It is occurring because of some setting on the user's PC
 
Hi

Yes, thanks for that. I've actually come to exactly the same conclusion. I think it an issue with an old version of a .dll on the machine, but I can't work out which .dll it is. Anyhoo as you say ElseIf can be used to circumvent the problem. If anyone knows which .dll it is I would be interested.

Thanks
Rob

Working Code:

If strFilePath Like "N:\TrustCancelledOps\Cancel2001.mdb" Then
Exit Sub 'if correct path/filename then no action needed
ElseIf strFilePath Like "N:\TrustC~1\Cancel2001.mdb" Then
Exit Sub ' where windows cuts the filepath down to 8 characters this is what CurrentDB.Name will return so have to have clause for this as well.
Else

MsgBox "The database is in the filepath " & strFilePath & " and is therefore not the live database. " & vbCrLf & _
"Please exit the database and contact the Access Reporting Team on 66477 for access to the correct database.", vbCritical, "Warning: Invalid Database File."

Cancel = True 'don't open this form (which tells them they are in live database) as they are not in live database

End If
 

Users who are viewing this thread

Back
Top Bottom