G
GollyJer
I use the function below to return the server or database name for various
uses.
However, now that we've switched to 2007 the line
CurrentDb.TableDefs(0).Connect
which used to return the connection string is returning an empty string.
Any ideas?
Thanks,
Jeremy
Function GetConnectionProperty(ServerOrDatabase As String) As String
' Returns name of connected server if "Server" passed in.
' Retuns name of connected Database if "Database" passed in.
Dim sConnectionString As String
Dim aConnectionPieces() As String
Dim sConnectionPiece As String
Dim i As Long
On Error Resume Next
sConnectionString = CurrentDb.TableDefs(0).Connect
aConnectionPieces = Split(sConnectionString, ";")
For i = LBound(aConnectionPieces) To UBound(aConnectionPieces)
sConnectionPiece = Mid$(aConnectionPieces(i), 1,
InStr(aConnectionPieces(i), "="))
If sConnectionPiece = "SERVER=" And UCase(ServerOrDatabase) = "SERVER"
Then
GetConnectionProperty = Mid$(aConnectionPieces(i), 8)
Exit For
End If
If sConnectionPiece = "DATABASE=" And UCase(ServerOrDatabase) =
"DATABASE" Then
GetConnectionProperty = Mid$(aConnectionPieces(i), 10)
Exit For
End If
Next i
End Function
uses.
However, now that we've switched to 2007 the line
CurrentDb.TableDefs(0).Connect
which used to return the connection string is returning an empty string.
Any ideas?
Thanks,
Jeremy
Function GetConnectionProperty(ServerOrDatabase As String) As String
' Returns name of connected server if "Server" passed in.
' Retuns name of connected Database if "Database" passed in.
Dim sConnectionString As String
Dim aConnectionPieces() As String
Dim sConnectionPiece As String
Dim i As Long
On Error Resume Next
sConnectionString = CurrentDb.TableDefs(0).Connect
aConnectionPieces = Split(sConnectionString, ";")
For i = LBound(aConnectionPieces) To UBound(aConnectionPieces)
sConnectionPiece = Mid$(aConnectionPieces(i), 1,
InStr(aConnectionPieces(i), "="))
If sConnectionPiece = "SERVER=" And UCase(ServerOrDatabase) = "SERVER"
Then
GetConnectionProperty = Mid$(aConnectionPieces(i), 8)
Exit For
End If
If sConnectionPiece = "DATABASE=" And UCase(ServerOrDatabase) =
"DATABASE" Then
GetConnectionProperty = Mid$(aConnectionPieces(i), 10)
Exit For
End If
Next i
End Function