Something new to think in the next few weeks
Thank you !
Private Sub ID_Student_BeforeUpdate(Cancel As Integer)
Dim StartDate As Date, TotalLogins As Long, LoginsThisWeek As Long
StartDate = VBA.DateTime.Date
Do Until Weekday(StartDate) = vbMonday
StartDate = DateAdd("d", -1, StartDate)
Loop
TotalLogins = DCount("ID_Student", "tblLogins", "ID_Student = " & Me.ID_Student)
Dim WhereClause As String
WhereClause = "[LoginDate] >= " & EnglishDate(StartDate) & " AND ID_Student = " & Me.ID_Student
LoginsThisWeek = DCount("ID_Student", "tblLogins", WhereClause)
Dim MsgTxt As String
MsgTxt = "The evil teacher say:" & vbCrLf & vbCrLf & _
"Total logins: " & TotalLogins & vbCrLf & _
"This week: " & LoginsThisWeek & vbCrLf & vbCrLf & _
"So, no more logins this week and..." & _
"NO ""sorry"" for this. Goodby !"
If LoginsThisWeek >= 2 Then
MsgBox (MsgTxt)
Cancel = True
Me.Undo
End If
End Sub
Oooh. I'm very sorry for this. I don't checked enough. :banghead:
Here is the code (Hope to work this time)
Code:Private Sub ID_Student_BeforeUpdate(Cancel As Integer) Dim StartDate As Date, TotalLogins As Long, LoginsThisWeek As Long StartDate = VBA.DateTime.Date Do Until Weekday(StartDate) = vbMonday StartDate = DateAdd("d", -1, StartDate) Loop TotalLogins = DCount("ID_Student", "tblLogins", "ID_Student = " & Me.ID_Student) Dim WhereClause As String WhereClause = "[LoginDate] >= " & EnglishDate(StartDate) & " AND ID_Student = " & Me.ID_Student LoginsThisWeek = DCount("ID_Student", "tblLogins", WhereClause) Dim MsgTxt As String MsgTxt = "The evil teacher say:" & vbCrLf & vbCrLf & _ "Total logins: " & TotalLogins & vbCrLf & _ "This week: " & LoginsThisWeek & vbCrLf & vbCrLf & _ "So, no more logins this week and..." & _ "NO ""sorry"" for this. Goodby !" If LoginsThisWeek >= 2 Then MsgBox (MsgTxt) Cancel = True Me.Undo End If End Sub
... and never will happen something if you don't change somethingBut Still. Nothing Happens with the code..
Take a paper sheet and write something like this:
Questions for my DB:
Q1 - How many students are in my DB ?
Q2 - How many students have a subscription for a certain course ?
Q3 - What courses should learn a student in a certain year of school ?
Q4 - What students has the middle name "H." ? (I know, this is stupid)
Q5 - .......
My code is designed to run under the BeforeUpdate event for a certain control (ID_Student)
Thanks a lot!!!Run-time error '3464':
Data type mismatch in criteria expression
This is a bit better (see attachment)
Warnings !!!
1) The DB will fill the tblLogin if or if not the student press the "Login" button.
2) The On Error statements are very useful but it is very dangerous as well.
The On Error Resume Next is the most dangerous and should be used ONLY in very special situations.
which is the StudentIsLoggedIn = false.compile error:
variable not defined