TryingMyBest
Registered User.
- Local time
- Today, 19:16
- Joined
- Nov 18, 2004
- Messages
- 54
What have I done wrong?
Ok...I tried SJ's code and it still adds the data to the table and doesn't display the error message....here's my code can you see where it has gone wrong please?
If I comment out exit sub then the error displays but it adds many new records to the table.
I've messed a bit more and it would seem that this code displays the error if none of the required fields are populated. I'm looking to have an error if one or more of the required fields aren't populated.
Thanks for all your help
A very confused Jo
Ok...I tried SJ's code and it still adds the data to the table and doesn't display the error message....here's my code can you see where it has gone wrong please?
Code:
Private Sub cmdAddToAudit_Click()
Dim ctl As Control
For Each ctl In Me
If ctl.Tag = "*" Then
If IsNull(ctl) Then
MsgBox "You must complete all relevant fields to continue", vbOKOnly, "Error"
ctl.SetFocus
Else
DoCmd.RunSQL "INSERT INTO TBLAuditRecords (ProgrammeNumber, ProjectName, TeamName, ProcessName, ResponsiblePerson, RPEMailAddress, Auditee, AEmailAddress, WBSCode, ReasonForAudit, AssignedAuditor, PlannedAuditDate, PlannedAuditDuration, AuditLocation, AuditNumber)" & _
"VALUES([Forms]![frmAuditProgrammePlanning]![txtProgrammeID], [Forms]![frmAuditProgrammePlanning]![cboProjectName], [Forms]![frmAuditProgrammePlanning]![cboTeamName], [Forms]![frmAuditProgrammePlanning]![cboProcessName], [Forms]![frmAuditProgrammePlanning]![txtResponsiblePerson], [Forms]![frmAuditProgrammePlanning]![txtEmailAddress], [Forms]![frmAuditProgrammePlanning]![txtAuditee], [Forms]![frmAuditProgrammePlanning]![txtAuditeeEmailAddress], [Forms]![frmAuditProgrammePlanning]![txtWBSCode], [Forms]![frmAuditProgrammePlanning]![cboReasonForAudit], [Forms]![frmAuditProgrammePlanning]![cboAuditorName], [Forms]![frmAuditProgrammePlanning]![txtPlannedAuditDate], [Forms]![frmAuditProgrammePlanning]![txtPlannedAuditDuration], [Forms]![frmAuditProgrammePlanning]![cboLocation], [Forms]![frmAuditProgrammePlanning]![txtAuditNumber])"
DoCmd.Requery "SUBAuditDetails"
DoCmd.Requery "cboAuditItem"
Exit Sub
End If
End If
Next
Set ctl = Nothing
End Sub
If I comment out exit sub then the error displays but it adds many new records to the table.
I've messed a bit more and it would seem that this code displays the error if none of the required fields are populated. I'm looking to have an error if one or more of the required fields aren't populated.
Thanks for all your help
A very confused Jo
Last edited: