T
TitaniaTiO2
Ok so I am spinning myself in circles.
Premise - I have a list of documents and a list of individuals. All
individuals are not trained to all documents. As a new history of a document
becomes effect, I need to document everyone's trainingcompletion dates for
that history.
I have the following tables:
tblDocument
DocumentNumber (key)
DocumentTitle
tblDocumentHistories
DocumentHistoryID (key)
DocumentNumber
DocumnetHistory
tblTrainingStatus
TrainingStatusID (key)
DocumentsForEachPersonID
DocumentHistoryID
TrainingDate
TrainingStatus
tblDocumentsForEachPerson
DocumentsForEachPersonID (key)
DocumentNumber
PersonID
DocumentActivity
I am working on one of my forms.
I want to be able to add a new document history to tblDocumentHistories (got
that) and add that same history to all the people who are trained to that
document (on tblTrainingStatus - here is where I am having problems)
Unfortunately the training date for all individuals for that document and
history are not the same.
Here is my code (no laughing at it... I know I probably went about things in
convoluted ways).
Private Sub cmdPreviewReport_Click()
On Error GoTo Err_cmdPreviewReport_Click
Dim stDocName As String
Dim DocumentHistoryID As String
Dim DocumentsForEachPersonID As Integer
MaxHistory = DMax("[DocumentHistory]", "[tblDocumentHistories]",
"[DocumentNumber] = '" & cmbDocumentNumber & "'")
strSQL = "SELECT tblDocumentHistories.DocumentNumber FROM
tblDocumentHistories"
strSQL = strSQL & " WHERE tblDocumentHistories.DocumentNumber = '" &
cmbDocumentNumber & "'"
strSQL = strSQL & " WHERE tblDocumentHistories.DocumentHistory = '"
& MaxHistory & "'"
OldDocumentHistoryID = DMax("[DocumentHistoryID]",
"[tblDocumentHistories]", "[DocumentNumber] = '" & cmbDocumentNumber & "'" &
" AND [DocumentHistory] = " & MaxHistory)
Set rs = CurrentDb.OpenRecordset("tblDocumentHistories", dbOpenTable,
dbAppendOnly)
rs.AddNew
rs!DocumentNumber = Me.cmbDocumentNumber
rs!DocumentHistory = Me.txtDocumentHistory
DocumentHistoryID = rs!DocumentHistoryID
rs.Update
Set rs = CurrentDb.OpenRecordset("tblTrainingStatus", dbOpenTable,
dbAppendOnly)
TotalRecords = DCount("[TrainingStatusID]", "tblTrainingStatus")
Text19 = TotalRecords
For i = 0 To TotalRecords
If rs!DocumentHistoryID = OldDocumentHistoryID Then
DocumentsForEachPersonID = rs!DocumentsForEachPersonID
rs.AddNew
rs!DocumentsForEachPersonID = DocumentForEachPersonID
rs!DocumentHistoryID = DocumentHistoryID
rs!TrainingStatus = "Training Document Issued"
End If
Next i
' stDocName = "rptNewSOPHistoryTrainingSheet"
' DoCmd.OpenReport stDocName, acPreview
Exit_cmdPreviewReport_Click:
Exit Sub
Err_cmdPreviewReport_Click:
MsgBox Err.Description
Resume Exit_cmdPreviewReport_Click
Resume
End Sub
The code executes but nothing in the For statement actually happens...no
additional lines are added to tblTrainingStatus.
What am I doing wrong?
Thanks!
Titania
Premise - I have a list of documents and a list of individuals. All
individuals are not trained to all documents. As a new history of a document
becomes effect, I need to document everyone's trainingcompletion dates for
that history.
I have the following tables:
tblDocument
DocumentNumber (key)
DocumentTitle
tblDocumentHistories
DocumentHistoryID (key)
DocumentNumber
DocumnetHistory
tblTrainingStatus
TrainingStatusID (key)
DocumentsForEachPersonID
DocumentHistoryID
TrainingDate
TrainingStatus
tblDocumentsForEachPerson
DocumentsForEachPersonID (key)
DocumentNumber
PersonID
DocumentActivity
I am working on one of my forms.
I want to be able to add a new document history to tblDocumentHistories (got
that) and add that same history to all the people who are trained to that
document (on tblTrainingStatus - here is where I am having problems)
Unfortunately the training date for all individuals for that document and
history are not the same.
Here is my code (no laughing at it... I know I probably went about things in
convoluted ways).
Private Sub cmdPreviewReport_Click()
On Error GoTo Err_cmdPreviewReport_Click
Dim stDocName As String
Dim DocumentHistoryID As String
Dim DocumentsForEachPersonID As Integer
MaxHistory = DMax("[DocumentHistory]", "[tblDocumentHistories]",
"[DocumentNumber] = '" & cmbDocumentNumber & "'")
strSQL = "SELECT tblDocumentHistories.DocumentNumber FROM
tblDocumentHistories"
strSQL = strSQL & " WHERE tblDocumentHistories.DocumentNumber = '" &
cmbDocumentNumber & "'"
strSQL = strSQL & " WHERE tblDocumentHistories.DocumentHistory = '"
& MaxHistory & "'"
OldDocumentHistoryID = DMax("[DocumentHistoryID]",
"[tblDocumentHistories]", "[DocumentNumber] = '" & cmbDocumentNumber & "'" &
" AND [DocumentHistory] = " & MaxHistory)
Set rs = CurrentDb.OpenRecordset("tblDocumentHistories", dbOpenTable,
dbAppendOnly)
rs.AddNew
rs!DocumentNumber = Me.cmbDocumentNumber
rs!DocumentHistory = Me.txtDocumentHistory
DocumentHistoryID = rs!DocumentHistoryID
rs.Update
Set rs = CurrentDb.OpenRecordset("tblTrainingStatus", dbOpenTable,
dbAppendOnly)
TotalRecords = DCount("[TrainingStatusID]", "tblTrainingStatus")
Text19 = TotalRecords
For i = 0 To TotalRecords
If rs!DocumentHistoryID = OldDocumentHistoryID Then
DocumentsForEachPersonID = rs!DocumentsForEachPersonID
rs.AddNew
rs!DocumentsForEachPersonID = DocumentForEachPersonID
rs!DocumentHistoryID = DocumentHistoryID
rs!TrainingStatus = "Training Document Issued"
End If
Next i
' stDocName = "rptNewSOPHistoryTrainingSheet"
' DoCmd.OpenReport stDocName, acPreview
Exit_cmdPreviewReport_Click:
Exit Sub
Err_cmdPreviewReport_Click:
MsgBox Err.Description
Resume Exit_cmdPreviewReport_Click
Resume
End Sub
The code executes but nothing in the For statement actually happens...no
additional lines are added to tblTrainingStatus.
What am I doing wrong?
Thanks!
Titania