Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Checking for duplicates using DCount

Status
Not open for further replies.

crisis2007

Technical User
Apr 2, 2007
114
US
I have a query that gives me the values in the T_Attendance table.The query works properly, getting its criteria from text boxes in my input form. I have this code on a command button that is supposed to give a message if I am trying to duplicate a date and a watch number:

------------

Private Sub Command0_Click()

Dim stDocName As String
Dim numActivity As Integer
Dim stLinkCriteria As String
Dim Cancel As Integer

numActivity = 0
numActivity = DCount("*", "Q_DupCheck_N1A")
If numActivity > 0 Then
MsgBox "A schedule for " & Me.txtAttendanceDate & " Watch " & Me.txtWatch & " already exists.", vbExclamation, _
"Wait a Minute!"
GoTo Exit_Command0_Click

End If


If Not IsNull(Forms!F_Input_N1A.txtAttendanceDate) Then

stDocName = "Q_Append"
DoCmd.OpenQuery stDocName, acNormal, acEdit

Forms!F_Input_N1A.SetFocus
DoCmd.Close

Else:
MsgBox "You need to put in a date above if you want to create a new schedule", vbExclamation, "What the...?"
Cancel = True
End If
Exit_Command0_Click:
Exit Sub



Err_Command0_Click:
MsgBox Err.Description
Resume Exit_Command0_Click


-------------



I get a message that pops up when I click the command button:

Run-time error '2001'
You canceled the previous operation.

Can anyone see what I am doing wrong? I have messed with this for hours now.


 
Never mind..... I figured it out. I spelled the form name incorrectly for the criteria in the query. ANother dumb mistake I find myself repeating too often.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top