• Home
  • Demo
  • Code
  • About
  • Contact

Code Snippets

In all the times I have spent participating in forum discussions about all sorts of users' questions, I have learnt a great deal from all the participants.

I have decided to post some of the sample codes that I found users were asking for almost all the time to help me keep them in one place and to make it easier for me to share them again and again.

Hope you find them useful.

 Opposite of DSum()

The Opposite of DSum()

Just in case anyone needs to perform the opposite of DSum() to create a query with a running difference, this function should provide the basics that can be adapted for your use (the idea came to me from a forum discussion):

Public Function DDiff(strField As String, strDomain As String, _
    			Optional strCriteria As String) As Variant

'Performs an aggregate difference
'Source: http://www.accessmvp.com/thedbguy
'7/26/2013

Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim strSQL As String
Dim varDiff As Variant

strSQL = "SELECT [" & strField & "] FROM [" & strDomain & "] "

If strCriteria > "" Then
    strSQL = strSQL & " WHERE " & strCriteria
End If

Set dbs = CurrentDb
Set rst = dbs.OpenRecordset(strSQL, dbOpenSnapshot)

With rst
    If Not (.BOF And .EOF) Then
        varDiff = .Fields(strField)
        .MoveNext
    End If
    Do While Not .EOF
        varDiff = varDiff - .Fields(strField)
        .MoveNext
    Loop
    .Close
End With

DDiff = varDiff

Set rst = Nothing
Set dbs = Nothing

End Function

 

Home | Demo | Code | About | Contact

 

Contents

  • Generate GUIDs
  • Backup and Compact BE
  • Get E-mail Address from AD
  • Get Network Username
  • Leigh's Generic Recordset
  • Trim Inner Spaces
  • Get Subform Control Name
  • The Opposite of DSum()
  • Concatenate Records
  • Get Network Domain Name
  • Get Computer Name
  • Get BE Info
  • Execute Action Queries
  • Extract Email Address

 

Copyright © 2012-2019, theDBguy™. All Right Reserved.
✉ theDBguy@gmail.com