DCount Error 2001

J

Jeefgeorge

I have a query that finds duplicate records in a table based on StdNo and
ProjNo - 2 StdNo can be the same, and 2 ProjNo can be the same, but the query
returns records where both the StdNo and ProjNo match. I have a module which
determines if this query is populated - if not, the table is exported to
excel. If so, then the duplicates are shown in a form so the user can either
delete one or make changes)

The code is run from a button on the switchboard. I have similar code which
runs from a command button on a form - this code works properly. The
difference between the two codes is that the query for the form pulls a
project number off the form and the query for the switchboard asks the user
for a project number.

When I debug the code for the switchboard, I get Error 2001 Previous action
cancelled and the debugger halts at the DCount Line

Here's my code for the switchboard:
Public Sub ExportEstimate()
'On Error GoTo Err_Export
Dim Dsktp, Tmplt, Msg As String, CurrentUser As Object, Warning As Integer
'Determine if any duplicate line items exist
If DCount("*", "FindDplctQt_") = 0 Then 'No Duplicates, Export Est
'Copy the ProjBook.xlt as ProjBook.xls on current user desktop
Set CurrentUser = CreateObject("Wscript.Shell")
Dsktp = CurrentUser.SpecialFolders("Desktop") & "\ProjBook.xls"
Tmplt = "R:\Data\Engineering Estimating Guide\ProjBook.xlt"
FileCopy Tmplt, Dsktp
'Transfer the General Project Info and Estimate to ProjBook.xls
DoCmd.TransferSpreadsheet acExport, 8, "Title", Dsktp, , "ProjInfo"
DoCmd.TransferSpreadsheet acExport, 8, "Dat_", Dsktp, , "BidtabRaw"
Else 'Duplicates Exist, display the duplicate items
Msg = "Duplicate Standard Line Items Exist!"
Warning = MsgBox(Msg, vbOKOnly, "Warning")
If Warning = 1 Then 'Ok was selected
DoCmd.OpenForm "GenEstDplctItems"
End If
End If
'Exit_Export:
' Exit Sub
'Err_Export:
' MsgBox Err.Description
' Resume Exit_Export
End Sub

Once again the only difference between this code and the code on the form is
the query whose criteria is [Form]![GenerateGuide]![ProjNo]. The criteria for
the query referenced above is [Enter Project Number].
 
K

Klatuu

The DCount can't use a parameter query. Here is a way you can do it. First,
remove the criteria from the query. Then use an input box to feed the value
to the Dcount:

If DCount("*", "FindDplctQt_", "[FieldToFilter] = """ & InputBox("Enter
FieldToFilter") & """") = 0 Then

Where [FieldToFilter] is the name of the field in the query you want to
filter on.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top