I'm using Access 2003 form as front end connecting to sql server 2000 backend via DSN to enter data to one table tblActivity. I need to validate four fields on the form to ensure that the user does not enter duplicate info into tblActivity. the columns are Community, Building, Unit, and Task. Once the user fill in the Task, I would like to search tblActivity to see if a record with the combination of these fields already exists. If so, tell the user 'Activity has already been entered' else add it as a new record. This is the code I have behind the Add button to add the record without the validation:
Private Sub cmdAdd_Click()
On Error GoTo Err_cmdAdd_Click
Dim strSQLAppend As String
strSQLAppend = "INSERT INTO dbo_tblActivity ([Community],[Building], [Unit],[Task],[Vendor],[Score1],[Score2],[Score3],[InspDate] )" & _
"SELECT [Forms]![frmDataEntry]![TxtCommunity],[Forms]![frmDataEntry]![TxtBuilding],[Forms]![frmDataEntry]![TxtUnit],[Forms]![frmDataEntry]![TxtTask],[Forms]![frmDataEntry]![TxtVend],[Forms]![frmDataEntry]![TxtScore1],[Forms]![frmDataEntry]![TxtScore2],[Forms]![frmDataEntry]![TxtScore3],[Forms]![frmDataEntry]![TxtBldrInspDt]"
DoCmd.SetWarnings (warningsoff)
DoCmd.RunSQL strSQLAppend
DoCmd.SetWarnings (warningson)
Me.CboCommumity = ""
Me.TxtBuilding = ""
Me.TxtUnit = ""
Me.CboTask = ""
Me.CboVendor = ""
Me.TxtScore1 = ""
Me.TxtScore2 = ""
Me.TxtScore3 = ""
Me.TxtInspDt = ""
Me.CboCommunity.SetFocus
Exit_cmdAdd_Click:
Exit Sub
Err_cmdAdd_Click:
MsgBox Err.Description
Resume Exit_cmdAdd_Click
End Sub
What code do I need to accomplish the validation and where do I place the validation code? Your help/suggestion is greatly appreciated.
Thanks
Private Sub cmdAdd_Click()
On Error GoTo Err_cmdAdd_Click
Dim strSQLAppend As String
strSQLAppend = "INSERT INTO dbo_tblActivity ([Community],[Building], [Unit],[Task],[Vendor],[Score1],[Score2],[Score3],[InspDate] )" & _
"SELECT [Forms]![frmDataEntry]![TxtCommunity],[Forms]![frmDataEntry]![TxtBuilding],[Forms]![frmDataEntry]![TxtUnit],[Forms]![frmDataEntry]![TxtTask],[Forms]![frmDataEntry]![TxtVend],[Forms]![frmDataEntry]![TxtScore1],[Forms]![frmDataEntry]![TxtScore2],[Forms]![frmDataEntry]![TxtScore3],[Forms]![frmDataEntry]![TxtBldrInspDt]"
DoCmd.SetWarnings (warningsoff)
DoCmd.RunSQL strSQLAppend
DoCmd.SetWarnings (warningson)
Me.CboCommumity = ""
Me.TxtBuilding = ""
Me.TxtUnit = ""
Me.CboTask = ""
Me.CboVendor = ""
Me.TxtScore1 = ""
Me.TxtScore2 = ""
Me.TxtScore3 = ""
Me.TxtInspDt = ""
Me.CboCommunity.SetFocus
Exit_cmdAdd_Click:
Exit Sub
Err_cmdAdd_Click:
MsgBox Err.Description
Resume Exit_cmdAdd_Click
End Sub
What code do I need to accomplish the validation and where do I place the validation code? Your help/suggestion is greatly appreciated.
Thanks