Warn user When the Data Being Entered 3 times (1 Viewer)

Thank You Lagbolt
 
Something new to think in the next few weeks :)
Thank you !

Hi Mihail: It takes time for me to realize that the code in the before update of the studentID field counts all the record. not the record with the same ID number. How will I do that?? counting the record with the same ID number only!!!


Thanks Again!!!
 
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
 
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

Hi Mihail. Here I am again. The code greatly works above. but when I cut the code and paste it in the login button of my final db and run the database nothing happens. it only adds the record. And here's may be the cause of problem. The Data type of the StudentID field is not a Number but instead a short text. Because they require me to have fix format of the ID numbers so I put input mask in it which is [0000-000]. Could you take a look in my final db. I really appreciate your help.
 

Attachments

Until I'll take a closer look, do this:

From any VBA module go to Tools -> Options -> and check the "Require Variable Declarations" check box.

Open each VBA module.
At the very top you should have this:
Option Compare Database
Option Explicit


So, manually add this:
Option Explicit

Close Access and SAVE !!!!!

Restart Access
Go again to a code module.
Go to Debug menu and click the Compile COMLAB bla bla bla option.

Inform me about the results.
 
Thanks for the reply. I did as what you have instructed. And the result I've found out that there are some codes that are not usable anymore in the database. I've also put:

Option Compare Database
Option Explicit

in each module.

But Still. Nothing Happens with the code.. I've learned something new today.. Thank You.
 
But Still. Nothing Happens with the code..
... and never will happen something if you don't change something :)
That was only for the debug purpose.

My code is designed to run under the BeforeUpdate event for a certain control (ID_Student)

But I saw that you moved it under the Click event for a button.
So... now you know what to do: Put the code at it's place

On the other hand:
I saw your "Final DB" and I'm wonder how you expect to help you.
This DB do... nothing.

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 - .......

After you are sure that you have ALL the question post it here and will try together to design the best DB we can.

Keep in mind that the actual design do not allow you to ask almost anything.
I assume that you don't need a nonfunctional DB with the best Login form in the world.
 
Thank you Mihail. I'll post back as soon as possible..
 
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 - .......

Here's how my db should:

1. Login Students (More likely 50 students per day)
2. Record the number of times a single student log in per week.
3. Limit each student to use Comlab 3 times per week only.
(Prompt the user if the student exceeds)


What I want to build is just a Simple logging system for the students.
 
My code is designed to run under the BeforeUpdate event for a certain control (ID_Student)

Hi Mihail. I've copy the code now under the BeforeUpdate event and delete it from the command button Click Event. Also I change the control from StudentID to ID_Student. And now, it produces this error:
Run-time error '3464':
Data type mismatch in criteria expression
Thanks a lot!!!
 
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.
 

Attachments

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.

I opened your attached db. But when I opened the form frmlogin an error message pop up:
compile error:
variable not defined
which is the StudentIsLoggedIn = false.
Do this [StudentIsLoggedIn] code has something to do with something? I don't know what is it for.. Can you tell me.?

And, what I did is I deleted the code and the db works PRETTY GOOD. I've just added some modification with it.


Thank you very much.
smile.gif
 
The variable was intended to say me if the student has pressed "Login" before the form to be closed.
By looking at this variable the Close event should remove the record from tblLogin if the student don't login. But, because a limited time, I can't develop the code.

Imagine this:
A student start (first time in a week) to login.
So, he/she fill the box with ID.
Then, he/she change his mind and press "Close".

Should this attempt to be considered as a "login" event ? I don't think so.
But your tblLogin is filled with the StudentID.
So, if the student press "Close" you should remove that record from the table.
 
Ah. I've got your point . Thanks for the Info Mihail:)
 

Users who are viewing this thread

Back
Top Bottom