Dynamic Form Elements in Access - vba

I am working on a project in Access 2016 and VBA, that contains a table that stores the details of students (StudentID, EnrollmentNo, Name, Center, etc) and another that contains the attendence (having fourcolumns: ID, StudentID, DateOfClass, IsPresent).
I want to create a form displaying multiple rows, each row belonging to a each student displaying (Enrollment No, Name, DateOfBirth, DateOfClass, IsPresent) and finally want to input the isPresent field using check box and then save the information for all/add new information.
Is there any way to do this ?
Here I am concerned about the form. How do I CREATE such a form (like Datasheet view) where I have a list of students column wise (with their details like enrollment number etc.) and IsPresent (check box type thing) in the next. So that If I like to input attendence in the attendance table I could just set the date and mark the checkboxes in front of students and then press a button which adds all the data to the table.

No table of classes/subjects? Only 2 tables? You have to do data entry into Attendance. Could only create records for students that attend so the IsPresent field would not be needed. If you want record for student even if not attending then, yes, need IsPresent.
If you want to 'batch' create records for all students for a particular date, run INSERT SELECT sql action.
INSERT INTO Attendance(StudentID, DateOfClass) SELECT StudentID, [enter date value] AS DateOfClass FROM Students;

Related

Creating a table having a group of attributes with same name

I am actually trying to create a student database and I need my table to be something of this type
In the above picture the date is something like a super-column name to columns-A,B,C,D which are subject names.
My data will be inserted in those A,B,C,D columns.
My final aim is to access attendance in all subjects based on the date.
Something like:-
select 27-01-2020 from 'table-name';
the above query should give me the attendance in all subjects on 27-01-2020 date
Is there any way to create such a table or similar to this one?
Assuming you have a table for the students and a table for the subjects, you could use a third table, representing the attendance of the students to the different subjects.
Such table will have a date, a reference to the subject, a reference to the student and an attendance column, possibly of type boolean, denoting if the student was present during that day at that subject. You may also add a slot, in case there are more than one hour of lecture for a subject on that day (but this is up to you and your needs).
There should also be a uniqueness constraint on the tuple (date, student, subject), so that there cannot be a student present at two different lectures the same day (unless you use the slot, to which the uniqueness constraint should also span).

MS Access Text Search Box with referenced values

Lets assume I have 2 tables: Projects and Employees. Each project got one responsible employee that I chose as a Lookup Value from the Employee table.
Now I understand that Access saves the ID of the employee in the project table and that's good. However, now I want to create a search query to get all projects with e.g. Mike as responsible person.
This is my code:
SELECT projects.name, projects.responsible
FROM projects
WHERE projects.responsible = Forms!form_search!employee_name;
Now it works fine if I type in the Form the employee ID but I cannot remember all IDs. I want to be able to type in 'Mike' in the Form and the query delivers me still all of Mike's projects.
How can I achieve that?
I thought about something like:
WHERE (projects.responsible = (employees.ID WHERE employees.name = Forms...));
But this doesn't work...
You can use a dropdown list with 2 columns as a filter criteria.
To fill this list, you make a request on your employee table, hide the first column (0cm wide) and the second column would display the matching employee name but your SQL request still receive the ID as criteria.
You should NOT have to modify your SQL request.

SQL table with a choice list (in pure SQL or with Java)

I am willing to create myself a table in a database I make.
I don't know how to create a choice list to fill fields.
I explain my problem more specifically.
I want to obtain something like this
......................................................
table Employees (just example)
.......................................................
index / Name / Profession
1 / John / Manager ..........<= here is the choice list between all possible jobs we have
How can I do this?
I want that my Employee table is editable (like in a GUI interface in Java), and that the values of profession can be edited (meaning, we can select a different value from the choice list).
Many thanks in advance for your help!
Tom
I recommend to have 2 tables in DB. one for employee and one for jobs..
In UI (java) to have the business to populate the drop down from jobs table.. when you save the UI info you have to write in both tables if is necessary.
e.g. Employee table: Id, name, job_id and Job table with Id, name. we need 2 methods one to read from employee and one to read from jobs. Dropdown have 3 properties: Id (id from job table, display - name from job table and binding value - job_id from employee table)
the drop down should have the options to add new values..
when you save in the db if you have new values in the job you have to add those values in the db and link to the employees

Crystal Reports SQL Expression

I am having trouble figuring out how to pull a value from a secondary table, to use as selection criteria on a per-record basis.
I am working with Crystal Reports 2011 on Windows 7, over an ODBC connection to an Oracle 11g database.
I am creating an employee directory that utilizes information from two locations:
table: TEACHERS
view: PVSIS_CUSTOM_TEACHERS
The teachers table is set up with your predictable fields: id, lastname, firstname, telephone, address, city, state, zip, etc. etc. etc.
The view has the following fields available:
TEACHERID
FIELD_NAME
TEXT_VALUE
The database application I am using allows me to create "custom fields" that are related back to the main teachers table. In truth, the fields I am creating are actually stored in a separate table, but are then accessible through the PVSIS_CUSTOM_TEACHERS view. Since the database application allows for any number of "custom fields" to be created, the view can have any number of records in it that can be tied back to the records within the teachers table.
There are MANY custom fields that have been created, but for the purposes of my current project, only 3 of them matter:
empDirSupRecord
empDirSupPhone
empDirSupAddr
The view for my personal teacher record would look like this:
TeacherID Field_Name Text_Value
1 empDirSupRecord
1 empDirSupPhone 1
1 empDirSupAddr 1
1 AnotherField another_value
1 YetAnotherField yetanother_value
(This would indicate that I've asked for my phone and address to be suppressed, but would still want my name to be included in the directory)
These fields will each contain a '1' if the user has asked that their phone number, or address not be published, or if we need to suppress the entire record altogether.
When I first started my report, I pulled both the table and view into the database expert and linked them together with teachers.id = pvsis_custom_teachers.teacherid. However, this causes each teacher's name to print on the report once for every record with their teacher id in the view. Since that's not the behavior I want, I removed the view from the database expert, and tried using SQL Expression fields to retrieve the contents of the custom field. This is where I'm currently stuck. I would need to write the sql in a way that selects the correctly named field, for each of the teacher records as the record is being processed by the report.
Currently, my sql expressions statement is written as:
(SELECT text_value FROM pvsis_custom_teachers WHERE field_name = 'empDirSupRecord' AND teacherid = '1')
What I need to do is figure out how to get the report to intelligently select the record for teacherid = (whatever teacherid is currently being processed). I'm not sure if SQL Expression fields are the way to go to accomplish this, so am definitely open to alternate suggestions if my current approach will not work.
Thanks for taking a look. :-)
You're almost there with the SQL Expression. You can refer back to the main query with double quoted field names. So what you're looking for is:
case when "teacher"."id" is null then null
else (SELECT max(text_value)
FROM pvsis_custom_teachers
WHERE field_name = 'empDirSupRecord' AND teacherid = "teacher"."id")
end
Note that CR will likely complain without the null check and use of max(), since it wants to be sure that only a scalar will ever be returned.
The alternative, and likely less-performance-intensive way to do this, is to join the table and view like you first described. Then, you can group by {teacher.id} and keep track of each field name in the view via variables. This will require more work and more formulas, though. Something like this, for example:
//Place this formula in the Group Header
whileprintingrecords;
stringvar empDirSupRecord:="";
//Place this formula in the Details section
whileprintingrecords;
stringvar empDirSupRecord;
if {pvsis_custom_teachers.field_name} = 'empDirSupRecord'
then empDirSupRecord:={pvsis_custom_teachers.text_value}
//Place this formula in the Group Footer
whileprintingrecords;
stringvar empDirSupRecord;

logical issue in sql query

I'm asked to create an application for employees attendance, and I have a logical problem:
I have emp table with id and name, the second table is attendance with id, empid, date, check (true or false), id is the PK.
There will be a form to submit each employee attendance by it self. The user will have a form with the name of employee with a drop down box populated with all employees and a date input text to add the date, and finally yes or no drop down box. My problem is the user can enter 1 or more attendance for the same date and the same employee, which might end with an employee with 40 days attendance in one month.
I'm using google apps engine with datastore, so, any suggestions to solve this issue?
You should be able to create a unique key (empid, date).
It works like a second primary key - does not alow duplicates.