Hi all,
I'm getting this return value of 0 in my message box which is supposed to return the number of records matching the date entered by user:
Any ideas on where I should change my code?
Initially, I was trying to use RecordCount, but I couldn't get it to work. I was wondering if I'm getting the "date" field into the query properly.
My code is:
I'm getting this return value of 0 in my message box which is supposed to return the number of records matching the date entered by user:
Any ideas on where I should change my code?
Initially, I was trying to use RecordCount, but I couldn't get it to work. I was wondering if I'm getting the "date" field into the query properly.
My code is:
Code:
Option Compare Database
Private Sub dtmVisit_Start_Date_LostFocus()
'This will warn you if there are too many jobs for a particular date and allow you to continue if you want
Dim rst As dao.Recordset
Dim BeginningSQL As String
Dim WhereSQL As String
Dim FinalSQL As String
If IsNull(Me.dtmVisit_Start_Date) Then
MsgBox "No Date Entered.", vbInformation
Exit Sub
Else
'the following SQL is copied direct from the query builder in access
BeginningSQL = "SELECT Count(*) As NumRecords FROM tblVisit WHERE "
'where the date field is equal to the one entered by the user AND where the enquiry is a live project
WhereSQL = "tblVisit.dtmVisit_Start_Date" & " = #" & Me.dtmVisit_Start_Date & "#;"
FinalSQL = BeginningSQL & WhereSQL
MsgBox FinalSQL
Set rst = CurrentDb.OpenRecordset(FinalSQL)
'If (rst.RecordCount > 2) Then
If vbYes = MsgBox("You currently have " & (rst("NumRecords")) & " entries for this (" _
& Me.dtmVisit_Start_Date & ") date, are you sure you wish to continue?", vbYesNo) Then
'MsgBox "Please continue as you were!", vbOKOnly
Me.dtmVisitTime.SetFocus
Else
MsgBox "Please choose another date", vbOKOnly
Me.dtmVisit_Start_Date = Date
Me.chrVisit_Type.SetFocus
End If
'Else
'MsgBox "This should only come up if less than or equal to 2", vbOKOnly
'Me.dtmVisitTime.SetFocus
'End If
'End With
End If
End Sub
Last edited: