Created
January 18, 2016 18:18
-
-
Save carlossaraiva/148168659355ade812a6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Private Sub Codigo_Aluno_Enter() | |
Dim MyRec As DAO.Recordset | |
Dim myVar | |
Set db = CurrentDb | |
Set MyRec = db.OpenRecordset("SELECT * FROM Cadastro Where Codigo_Aluno = " & Chr$(39) & Codigo_Aluno.Text & Chr$(39)) | |
If MyRec.RecordCount > 0 Then | |
Label5.Caption = MyRec.Fields("Nome") | |
CurrentDb.Execute ("INSERT INTO Entrada (Codigo_Aluno) VALUES (" + Codigo_Aluno.Text + ")") | |
End If | |
'Remontando a a tabela de lista de presenças | |
Dim rsCadastro As DAO.Recordset | |
Dim rsEntrada As DAO.Recordset | |
Dim strSQL1 As String | |
Dim strSQL2 As String | |
Dim intI As Integer | |
strSQL1 = "SELECT * FROM Cadastro" | |
strSQL2 = "SELECT DISTINCT format(Entrada.Data," & Chr$(39) & "Short Date" & Chr$(39) & ") as data FROM Entrada" | |
Set rsCadastro = db.OpenRecordset(strSQL1) 'Recordset de Cadastro | |
Set rsPeriodo = db.OpenRecordset(strSQL2) 'Recordset valores distintos de periodo | |
'Se listagem de cadastro retornar nada, a função é terminada. | |
If rsCadastro.EOF Then Exit Sub | |
'Codigo supostamente começa aqui | |
'Exclusao do conteudo da tabela de Lista | |
db.Execute ("delete from ListaPresença") | |
'Geração da tabela ListaPresenca. | |
'Primeiro retorno a lista de alunos cadastros. Depois um lista de periodos registrado. Assim é possivel verifica quem tem algum registro na tabela ou não. | |
Do While Not rsCadastro.EOF | |
rsPeriodo.MoveFirst | |
Do While Not rsPeriodo.EOF | |
dataInicial = Format(rsPeriodo!Data, "mm/dd/yyyy") | |
dataFinal = Format(DateAdd("d", 1, rsPeriodo!Data), "mm/dd/yyyy") | |
query = "SELECT data FROM Entrada Where Data between #" & dataInicial & "# And #" & dataFinal & "# AND Codigo_Aluno = " & Chr$(39) & rsCadastro!Codigo_Aluno & Chr$(39) | |
Set rsEntrada = db.OpenRecordset(query) | |
If rsEntrada.RecordCount > 0 Then | |
insertQuery = "INSERT INTO ListaPresença (Data, Codigo_Aluno, Presenca) VALUES(#" & Format(rsEntrada!Data, "mm/dd/yyyy 00:00:00") & "#," + rsCadastro!Codigo_Aluno + ", True)" | |
db.Execute (insertQuery) | |
Else | |
db.Execute ("INSERT INTO ListaPresença (Data, Codigo_Aluno, Presenca) VALUES(#" & Format(rsPeriodo!Data, "mm/dd/yyyy") & "#," + rsCadastro!Codigo_Aluno + ", False)") | |
End If | |
rsPeriodo.MoveNext | |
Loop | |
rsCadastro.MoveNext | |
Loop | |
'Criacao de uma tabela com lista de faltas | |
db.Execute ("drop table ListaAusentes") | |
db.Execute ("create table ListaAusentes") | |
db.Execute ("Alter Table ListaAusentes ADD COLUMN ID number") | |
Dim rsNomes As DAO.Recordset | |
rsCadastro.MoveFirst | |
i = 0 | |
Do While Not rsCadastro.EOF | |
insertSql = "Insert INTO ListaAusentes(ID) values (" & i & ")" | |
db.Execute (insertSql) | |
i = i + 1 | |
rsCadastro.MoveNext | |
Loop | |
rsPeriodo.MoveFirst | |
Do While Not rsPeriodo.EOF | |
i = 0 | |
dataInicial = Format(rsPeriodo!Data, "mm/dd/yyyy") | |
dataFinal = Format(DateAdd("d", 1, rsPeriodo!Data), "mm/dd/yyyy") | |
Dim teste As String | |
teste = "'" & CStr(Format(dataInicial, "mm/dd/yyyy")) & "'" | |
db.Execute ("Alter Table ListaAusentes ADD COLUMN" & teste & " text(255)") | |
'query = "SELECT Cadastro.Nome FROM ListaPresença INNER JOIN Cadastro on Cadastro.Codigo_Aluno = ListaPresença.Codigo_aluno Where Data between #" & dataInicial & "# And #" & dataFinal & "# AND PRESENCA = FALSE" | |
query = "SELECT Cadastro.Codigo_Aluno, Cadastro.Nome FROM ListaPresença INNER JOIN Cadastro on Cadastro.Codigo_Aluno = ListaPresença.Codigo_aluno Where Data >= #" & dataInicial & "# And Data < #" & dataFinal & "# AND PRESENCA = FALSE" | |
Set rsNomes = db.OpenRecordset(query) | |
Do While Not rsNomes.EOF | |
updateSql = "Update ListaAusentes SET " & teste & " = '" & rsNomes!Codigo_Aluno & "' Where ID = " & i | |
db.Execute (updateSql) | |
rsNomes.MoveNext | |
i = i + 1 | |
Loop | |
rsPeriodo.MoveNext | |
Loop | |
rsCadastro.Close | |
rsEntrada.Close | |
rsPeriodo.Close | |
db.Close | |
Set rsCadastro = Nothing | |
Set rsEntrada = Nothing | |
Exit Sub | |
End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment