Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default 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
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
UDF's shane Excel Discussion (Misc queries) 4 March 24th 10 03:37 PM
UDF's using other UDF's millsy Excel Worksheet Functions 9 December 18th 05 08:38 PM
What UDF's are being used? SkylineGTR Excel Programming 3 November 22nd 05 10:01 AM
Argument help for UDF's Jan Kronsell Excel Programming 2 November 6th 05 12:19 PM
UDF's jim c. Excel Programming 2 November 18th 04 08:33 AM


All times are GMT +1. The time now is 11:01 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"