Having some issues with VBA in Access 2013

Status
Not open for further replies.

spdragoo

Expert
Ambassador
OK, first off, this is not for an assignment.

My wife works at the local community college. They've been assigned to take over the English & Math placement testing. The tests are computerized, & if the students don't place as high as they'd like they have the option of going through at least 5 hours of computerized "remediation" (i.e. practice test questions) before retaking it. They can then retake it until a) they get the placement they want, or b) they've enrolled in a class (including Developmental Education/remedial-level courses).

The catch is that the college didn't budget for a separate computer lab, so they're forced to use the existing computer tutoring lab. That's a lot of double-duty, especially for the staff (since most of the tutors don't have the credentials to teach, & they want instructors available).

So, my wife asked if I could come up with some way that they could track how many students come to the lab & why they're in the lab (i.e. testing, remediation, tutoring, etc.). They want to be able to track the number by day of the week, by the hour, & how long the students are there. They don't need to know by individual student, though, & in many cases those students may not even be enrolled, so they won't have a student ID number.

I thought I could maybe set up an Access database & use VBA for data validation & some of the data entry. I have the following:
-- table (Students_in_Lab) with fields for their name (StudentName), date & start/end times they are in the lab, & total time in the lab
-- Login form (Student_Login) where they enter their name, & where the VBA code determines if they're logging in or logging out;
-- Secondary forms (Login_Option & Logout_Option): the latter tells them they've been logged out, the former has them select a reason for using the lab.

I wanted to test my VBA code to see if it was working, so I have it tell me if the name is in the table. Right now it uses MsgBox to give the result of that test (True/False) & either a logged-in or logged-out message, so that I could test its ability to find a student's name.

But...it's not working. I used my own name & multiple names in the table, so I should be getting a "True" message if I use one of them, but instead I always get "False" for the first message.

This is the code I have:

Code:
Private Sub CommandOK_Click()
    Dim nameexists As Variant
    Dim namecheck As Boolean
        
    nameexists = DLookup("StudentName", "Students_in_Lab", "StudentName = '" & Forms!Student_Login!Student_Name & "'")
    namecheck = IsNull(nameexists)
    
    Response = MsgBox(namecheck, vbOKOnly, nameexists)

    If namecheck = True Then
        Response = MsgBox("Logoff successful", vbOKOnly, "Logged Out")
    Else
        Response = MsgBox("Login successful", vbOKOnly, "Logged In")
    End If
        
    
End Sub

I'm not sure where I'm going wrong on this, or if I should just chuck it & try writing it in VisualBASIC (or something else) instead. The only thing is, I wanted to be able to create reports in Access with it, so I'd prefer sticking to Access if at all possible.
 
Solution
Disclaimer..yes, I do know more than a fair bit of access & VBA.

OK..
From a UI viewpoint, there are a few gotchas.

1. The StudentName must be in a selectable dropdown. Otherwise, you will get many false duplicates if they can free entry their name.
The db will see johnjones as a different person than john jones

2. What happens if John fails to log out? (this WILL happen)

3. What happens if Mary logs out Johnny?


Once we have those things figured out...this is how I'd design it.

Up front, you need a table with the actual names of all students. (And an admin form to edit this)

2 forms visible onscreen, LogIn and LogOut.
If you are currently not logged in, your name appears in the dropdown on the LogIn form...

USAFRet

Titan
Moderator
Disclaimer..yes, I do know more than a fair bit of access & VBA.

OK..
From a UI viewpoint, there are a few gotchas.

1. The StudentName must be in a selectable dropdown. Otherwise, you will get many false duplicates if they can free entry their name.
The db will see johnjones as a different person than john jones

2. What happens if John fails to log out? (this WILL happen)

3. What happens if Mary logs out Johnny?


Once we have those things figured out...this is how I'd design it.

Up front, you need a table with the actual names of all students. (And an admin form to edit this)

2 forms visible onscreen, LogIn and LogOut.
If you are currently not logged in, your name appears in the dropdown on the LogIn form.
Select your name, type in a reason, and click the Log Me In button.
Said button runs a bit of code (Update query) to write a Yes to the LoggedInStatus table (or just a field in the Student table), and grabs the System Time ( NOW() ) and writes that to the relevant When field. Along with reason and anything else.

The LogIn screen refreshes, and the query that feeds the Name dropdown no longer shows that person.
They cannot log in twice.

The LogOut form has a similar dropdown.
Does mostly the same thing. Select your name, click the LogMeOut button.
Grabs the system time, and changes the LoggedInStatus to No.

mgbox popsups as needed.

The forms again refresh, and your name disappears from the dropdown on the LogOut form, and appears on the LogIn form, ready for tomorrow, or later today.

 
Solution
For the immediate problem try putting the field name in brackets:

nameexists = DLookup("[StudentName]", "Students_in_Lab", "[StudentName] = '" & Forms!Student_Login!Student_Name & "'")

I haven't kept up with Access so you may need to do some string trim()s also to get matches.

USAF's concerns are valid so you probably need to separate names to first, middle initial, and last and do some otherwork but the above code should give you something to work with.
 

spdragoo

Expert
Ambassador


1. The dropdown list would only work if they knew ahead of times which potential students would be showing up. There are a lot of classes (at ~30 students per class) to have hard-coded in...& the problem is there's no way to then account for the incoming students, since they haven't registered for a class yet (once they register & start a Math/English class, they're no longer able to take the placement test). Plus, while the majority are going to be remedial students, I would imagine that most (if not all) should be able to spell their own name, & notice if it's misspelled before they click the OK button.

More importantly, though, it needs to differentiate between each and every visit that each student makes. John Jones, for example, might come in & stay there for 5 hours straight to do his remedial work before retaking the test, but Jane Smith might come in at 8 AM for an hour, come back later at 11AM for another hours, & then come back at 2 PM & spend 3 hours straight in the lab. John counts as one visit, while Jane counts as three visits.

2. I plan to have a script that will run at shutdown that goes through the table. If it finds an entry with an arrival time but no departure time, it'll automatically add in a departure time 1 hour after the arrival time. I had asked my wife about it, & she felt that if the students couldn't bother to log out, they should only count for an hour's worth of time. From the way she's described the students in the lab, most of them don't stay for much longer than an hour or 2 anyway.

That will come after I can get this part nailed down, though.

3. Well, Mary would have to know Johnny (maybe they're friends, maybe they take classes together, etc.) to be able to type in his name to log him out. I would be afraid that, by having a drop-down list, it would be a lot easier for someone to mistakenly log someone else out instead of themselves. They're not tracking this for grading purposes, the instructors just want to know how many students are coming in so that they know how much staffing they need, & to identify the zenith & nadir points on the traffic.



Hmmm....

OK, that...

Argh, that's a lot simpler than what I was working with. And it would be a lot simpler for the students & instructors (my wife is pretty tech-savvy, but compared to a lot of her co-workers would be considered a tech genius). Plus, I already have bookmarked a site that had free code for using a hidden form to also automatically refresh the forms after a specified time interval.

The only downside is I don't know if they'll have access to the names of the students, especially those that will be coming in for the 5 hours of remediation. But...they have to somehow show that they've done 5 hours of remedial work before retaking the placement test, so there must be a list somewhere that tracks those students-to-be. I'd have to check with my wife on that.

As for the MsgBox stuff, I mainly added those because I was previously getting run-time errors, so I added them to help track the VBA code flow.

OK, follow-up question. Access 2013 allow the database to be developed as a traditional or a web-based application, but the web-based versions require access to a SharePoint account. My wife has one, but I'm developing this on our home PC, so I don't have access to it. Is this the kind of application that would work better as a web-based application (with the instructors having full access to the back-end portion)? If so, is it fairly easy to convert a traditional database to the web-based format, or would it be better to switch over & try developing the web-based version from scratch?
 

USAFRet

Titan
Moderator
Student names.
Either have an admin person enter the name in the list...
OR

A button for "Is this your first time here? Please enter your name and Student ID"
This create a row for that person in the Student Table.

After that, they log in and out as above.
They only enter their name 1 time.

Prevent collisions by checking to see if there is already a "John Jones" and appending "2" - "John Jones2"
Or something like that.
Or possibly concatenate LastName and StudentID as their unique identifier for the data that goes int he dropdown.

"JonesQWE1234"



web based or strictly local?
Is there any real need for it to be web based. This is a pretty basic thing. I can't help but think that pushing it out to a web platform would just increase complexity.


More importantly, though, it needs to differentiate between each and every visit that each student makes. John Jones, for example, might come in & stay there for 5 hours straight to do his remedial work before retaking the test, but Jane Smith might come in at 8 AM for an hour, come back later at 11AM for another hours, & then come back at 2 PM & spend 3 hours straight in the lab. John counts as one visit, while Jane counts as three visits.
Not a problem
When someone logs in, it creates a new row in the Status table.
Student - John
Login Time - 1704
Reason -
LogOut Time - 1809

Tomorrow, when he logs in....a new row.

A query to feed a report (or form) showing how much cumulative time John has spent in the lab.
"John...you have 45 minutes left on your commitment"
 

USAFRet

Titan
Moderator
SharePoint vs Access.

Which one depends on the actual use.

If this is one (or two)classroom/lab, Access, contained on a PC in the lab.

If this is across multiple rooms and a few thousand students....A SharePoint solution may be required.
And for the non-complexity of this, you do NOT have to build it in Access first then port it to SP.
This could be built from the start, strictly in SP.

Either way could be very, very easy, with very little 'code' needed.
 

spdragoo

Expert
Ambassador


One, maybe 2 physical labs, all of which would have access to the same network drive that the faculty use.

So I think I'll stick with a standard Access database.

Thank you so much for the advice, BTW.
 
Status
Not open for further replies.