+ Reply to Thread
Results 1 to 2 of 2

Some helpful UDF's

  1. #1
    Jeremy Gollehon
    Guest

    Some helpful UDF's

    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

    ----------------------------------------------------------------------------------



  2. #2
    Jeremy Gollehon
    Guest

    Re: Some helpful UDF's

    Whoops, wrong forum. Sorry!

    Jeremy Gollehon wrote:
    > 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
    >
    > ----------------------------------------------------------------------------------



+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1