Question : How can I fill a list box which shows if no contact have been made in the last 90 days and no file has been added to a specific folder in the last 90 days in MS Access forms with VBA?


I have the following sets of code. These codes generate alerts when there has not been contact in the last 90 days, or folder has not been updated in 90 days.

this part is for the contacts

  If DateDiff("d", DMax("DateTime1", "ComCon", "FundName='" & Me.FundName & "'"), Date) > 90 The

this part is for the files (check if a new file created in a specific folder in the last 90 days or not)
Public Function NewestFileInFolder(strFolderPath As String) As Integer
    Dim objFSO As FileSystemObject, objFolder As Object, objFile As File, intTemp As Integer, bolFirstPass As Boolean
    Set objFSO = CreateObject("Scripting.FileSystemobject")
    Set objFolder = objFSO.GetFolder(strFolderPath)
    bolFirstPass = True
    For Each objFile In objFolder.Files
        intTemp = DateDiff("d", objFile.DateCreated, Date)
        If bolFirstPass Then
            NewestFileInFolder = intTemp
            bolFirstPass = False
        Else
            If intTemp < NewestFileInFolder Then NewestFileInFolder = intTemp
        End If
    Next
    Set objFile = Nothing
    Set objFolder = Nothing
    Set objFSO = Nothing
End Function

This both feed into a Form10 which is specific for an entry (specific for a fund). These are only for one fund.

I would like to create the same thing which goes and searches all the funds , and brings out all the attention required fields in the whole database. And lists them on a list box.

thanks
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
Private Sub Form_Current()
        
    If DateDiff("d", DMax("DateTime1", "ComCon", "FundName='" & Me.FundName & "'"), Date) > 90 Then
        Me.lstAlerts.AddItem ("UpdateContacts, Update the contacts: it has been more than 90 days")
    End If
    
    If NewestFileInFolder(Me.Folder) >= 90 Then

     Me.lstAlerts.AddItem ("UpdateFiles , Update the files: it has been more than 90 days")
' Me.lstAlerts.AddItem ("UpdateFiles , Update the files: it has been more than 90 days")

    End If

    
    
    

End Sub

Private Sub Form_Load()

    Dim intX As Integer
    
    For intX = 0 To Me.lstAlerts.ListCount - 1
        Me.lstAlerts.RemoveItem (intX)
    Next intX
    
    
    End Sub

Private Sub lstAlerts_DblClick(Cancel As Integer)

    Select Case Me.lstAlerts.Value
        Case "UpdateContacts"
            DoCmd.OpenForm "comform", , , "FundName='" & Me.FundName & "'", , acDialog
    End Select
    
     
End Sub


Public Function NewestFileInFolder(strFolderPath As String) As Integer
    Dim objFSO As FileSystemObject, objFolder As Object, objFile As File, intTemp As Integer, bolFirstPass As Boolean
    Set objFSO = CreateObject("Scripting.FileSystemobject")
    Set objFolder = objFSO.GetFolder(strFolderPath)
    bolFirstPass = True
    For Each objFile In objFolder.Files
        intTemp = DateDiff("d", objFile.DateCreated, Date)
        If bolFirstPass Then
            NewestFileInFolder = intTemp
            bolFirstPass = False
        Else
            If intTemp < NewestFileInFolder Then NewestFileInFolder = intTemp
        End If
    Next
    Set objFile = Nothing
    Set objFolder = Nothing
    Set objFSO = Nothing
End Function
with help from
"Blue Devil Fan" and "DatabaseMX"

Answer : How can I fill a list box which shows if no contact have been made in the last 90 days and no file has been added to a specific folder in the last 90 days in MS Access forms with VBA?

You could build both of these checks into query criteria.  You can pass the necessary fund information into each function and it can return back the number of days.  However, depending on how many funds you have, this could be really slow to do on the fly.  It might be better to build a work table with the information and then allow the user to refresh it when necessary.  Then you can base the listbox on that work table.

Or, you can denormalize a bit and store the LastContactDate and LastFileDate in the Fund table, refreshing those as necessary.  That would probably be my preference.  In our shop, we designate calculated fields with a suffix of _CALC so that nobody mistakenly allows the user to change it in the UI.
Random Solutions  
 
programming4us programming4us