I've got the following code on a form. The entirety of the sub is listed just in case. The relevant portion is below.
The part I'm having trouble with follows:
The intent of that (incomplete) ElseIf is to provide a list of all NANUnumbers that have expired. When a single NANU expires, the DLookup works perfectly since the query only has one record. But I'm stumped on dealing with anything more than one value.
The desired result is that the value from the NANUnumber field of each resulting record in qryNotifyExpiredNANU would be used to build a string for use in the MsgBox.
Using DLookup is out (I think) because I can't identify which records the query returned to apply a WHERE clause.
I also looked into using Loop with a RecordSet, but can't figure out how to approach it.
So to sum it up, I don't know how to grab each value present in the query and I also don't know how to concatenate a string with a dynamic number of values.
Code:
Private Sub Form_Timer() 'timer set to fire once per minute
'AutoPurge old records (>7yrs) and take action if Hotword and/or NANU expire
Dim Minute As String
Minute = Right(Format(TimeValue(Now()), "hh:mm"), 1)
'Only run these every 10 minutes
If Minute = "0" Then
DoCmd.SetWarnings False
DoCmd.OpenQuery "qryPurgeEmail"
DoCmd.OpenQuery "qryPurgeHotword"
DoCmd.OpenQuery "qryPurgeIIP"
DoCmd.OpenQuery "qryPurgeNANU"
DoCmd.OpenQuery "qryPurgeOutage"
DoCmd.OpenQuery "qryPurgeWatchLog"
DoCmd.OpenQuery "qryHotwordUpdateExpired"
'check if any NANUs will expire before doing it - if yes, notify user
If DCount("*", "qryNotifyExpiredNANU") = 1 Then
MsgBox "The NANU " & DLookup("NANUnumber", "qryNotifyExpiredNANU") & " has expired. It has been removed from the Active NANU list.", vbOKOnly, "NANU Expired"
ElseIf DCount("*", "qryNotifyExpiredNANU") > 1 Then
MsgBox "The NANUs " & !!!!RETRIEVED VALUE HERE!!!! & " and " & !!!!RETRIEVED VALUE HERE!!!! & " have expired. They Have been removed from the Active NANU list.", vbOKOnly, "NANU Expired"
End If
DoCmd.OpenQuery "qryNANUupdateExpired"
DoCmd.SetWarnings True
'refresh lists
Me.listActiveEmails.Requery
Me.listActiveNANUs.Requery
Me.listActiveOutages.Requery
Me.listAllEmail.Requery
Me.listIIPEmails.Requery
Me.listWatchLog.Requery
End If
'Popup reminders for watch entries
Dim db As DAO.Database
Dim rs As DAO.Recordset
Set db = CurrentDb()
Set rs = db.OpenRecordset("qryReminders")
With rs
If .RecordCount <> 0 Then
Do Until .EOF
MsgBox rs!RemindMessage, vbOKOnly, "Daily Routine Reminder"
rs.Edit
rs!LastRemindDate = Date
rs.Update
rs.MoveNext
Loop
End If
End With
rs.Close
End Sub
The part I'm having trouble with follows:
Code:
If DCount("*", "qryNotifyExpiredNANU") = 1 Then
MsgBox "The NANU " & DLookup("NANUnumber", "qryNotifyExpiredNANU") & " has expired. It has been removed from the Active NANU list.", vbOKOnly, "NANU Expired"
ElseIf DCount("*", "qryNotifyExpiredNANU") > 1 Then
MsgBox "The NANUs " & !!!!RETRIEVED VALUE HERE!!!! & " and " & !!!!RETRIEVED VALUE HERE!!!! & " have expired. They Have been removed from the Active NANU list.", vbOKOnly, "NANU Expired"
End If
The intent of that (incomplete) ElseIf is to provide a list of all NANUnumbers that have expired. When a single NANU expires, the DLookup works perfectly since the query only has one record. But I'm stumped on dealing with anything more than one value.
The desired result is that the value from the NANUnumber field of each resulting record in qryNotifyExpiredNANU would be used to build a string for use in the MsgBox.
Using DLookup is out (I think) because I can't identify which records the query returned to apply a WHERE clause.
I also looked into using Loop with a RecordSet, but can't figure out how to approach it.
So to sum it up, I don't know how to grab each value present in the query and I also don't know how to concatenate a string with a dynamic number of values.