Hi
I have a db for some property maintenance. I have some code on the 'on open' function on my Nav form which checks some safety check dates within a safety check table and if a check is due within 30 days a simple alert pops up to remind me.
I now want the code to check the dates in two fields with the table but im not sure how to code a second field within the same table to be checked.
Here is the code I use: (Have commented out some of code)
Private Sub Form_Open(Cancel As Integer)
On Error GoTo err
Dim db As DAO.Database
Dim Rst As DAO.Recordset
Set db = CurrentDb
Set Rst = db.OpenRecordset("tblSafetyChecks")
'If there are no records in the table, just exit
If Rst.EOF Then Exit Sub
'Loop over all the records in the table until the end of file
Do Until Rst.EOF
'If the date is not entered, do not evaluate
If Len(Nz(Rst!NextCheckA)) > 0 Then
'Handle 30 days
If DateDiff("d", Now(), Rst!NextCheckA) < 30 Then
MsgBox Rst!NextCheckA & ": Next Safety/Legal Check(s) Due! (Within 30 Days) ", vbOKOnly, "ALERT! Safety/Legal Check(s) Due "
'Else, handle 60 days
'ElseIf DateDiff("d", Now(), rst!NextCheck) < 60 Then
' MsgBox rst!NextCheck & " is less than 60 days away!"
'Else, handle 90 days
'ElseIf DateDiff("d", Now(), rst!NextCheck) < 90 Then
'MsgBox rst!NextCheck & " is less than 90 days away!"
'Its far away
'Else
'MsgBox "Chillax! You've got time.
" & vbCrLf & vbCrLf & "NextCheck:" & rst!NextCheck
End If
End If
'Think of a recordset as a table in memory. When we opened the table with the set rst=... command,
'the table opened, and there is a pointer at the first record.
'We have to tell the pointer to go to the next record
Rst.MoveNext
'Go back to the DO statement above and start over
Loop
'We opened some objects in our computers memory, we have to close them
On Error Resume Next
Set db = Nothing
Rst.Close
Set Rst = Nothing
Exit Sub
'This is called an error handler
'Should an error occur, this function will alert you to the error, and then stop running
err:
MsgBox err.Number & ": " & err.Description
End Sub
I want to add another field to be checked called 'NextCheck' as well as the existing field 'NextCheckA'.
Im a beginner so can say I have generated this existing code with help of other users.
Thanks
I have a db for some property maintenance. I have some code on the 'on open' function on my Nav form which checks some safety check dates within a safety check table and if a check is due within 30 days a simple alert pops up to remind me.
I now want the code to check the dates in two fields with the table but im not sure how to code a second field within the same table to be checked.
Here is the code I use: (Have commented out some of code)
Private Sub Form_Open(Cancel As Integer)
On Error GoTo err
Dim db As DAO.Database
Dim Rst As DAO.Recordset
Set db = CurrentDb
Set Rst = db.OpenRecordset("tblSafetyChecks")
'If there are no records in the table, just exit
If Rst.EOF Then Exit Sub
'Loop over all the records in the table until the end of file
Do Until Rst.EOF
'If the date is not entered, do not evaluate
If Len(Nz(Rst!NextCheckA)) > 0 Then
'Handle 30 days
If DateDiff("d", Now(), Rst!NextCheckA) < 30 Then
MsgBox Rst!NextCheckA & ": Next Safety/Legal Check(s) Due! (Within 30 Days) ", vbOKOnly, "ALERT! Safety/Legal Check(s) Due "
'Else, handle 60 days
'ElseIf DateDiff("d", Now(), rst!NextCheck) < 60 Then
' MsgBox rst!NextCheck & " is less than 60 days away!"
'Else, handle 90 days
'ElseIf DateDiff("d", Now(), rst!NextCheck) < 90 Then
'MsgBox rst!NextCheck & " is less than 90 days away!"
'Its far away
'Else
'MsgBox "Chillax! You've got time.
End If
End If
'Think of a recordset as a table in memory. When we opened the table with the set rst=... command,
'the table opened, and there is a pointer at the first record.
'We have to tell the pointer to go to the next record
Rst.MoveNext
'Go back to the DO statement above and start over
Loop
'We opened some objects in our computers memory, we have to close them
On Error Resume Next
Set db = Nothing
Rst.Close
Set Rst = Nothing
Exit Sub
'This is called an error handler
'Should an error occur, this function will alert you to the error, and then stop running
err:
MsgBox err.Number & ": " & err.Description
End Sub
I want to add another field to be checked called 'NextCheck' as well as the existing field 'NextCheckA'.
Im a beginner so can say I have generated this existing code with help of other users.
Thanks