Below find some helpful UDF's I wrote recently. I'm wondering if there are
other ways you guys might approach the tasks they accomplish. Word wrap
will probably be a problem as some of the lines are wide.
-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
----------------------------------------------------------------------------------
Function DAORecordCount(SourceForm As Access.Form) As Long
' Returns a reliable recordcount from a form.
With SourceForm.RecordsetClone
If .AbsolutePosition > -1 Then
.MoveLast
DAORecordCount = .RecordCount
Else
DAORecordCount = 0
End If
End With
End Function
----------------------------------------------------------------------------------
Function IsRecordSourceQuery(FormToCheck As Access.Form) As Boolean
On Error Resume Next
IsRecordSourceQuery =
Len(CurrentDb.QueryDefs(FormToCheck.RecordSource).SQL) > 0
End Function
----------------------------------------------------------------------------------
Function IsRecordSourceTable(FormToCheck As Access.Form) As Boolean
On Error Resume Next
IsRecordSourceTable =
Len(CurrentDb.TableDefs(FormToCheck.RecordSource).Name) > 0
End Function
----------------------------------------------------------------------------------
Bookmarks