[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

type Mismatch DCount value

Posted on 2014-02-18
6
Medium Priority
?
589 Views
Last Modified: 2014-02-20
I am getting type mismatch when I need to get a record count based on the following dCount. (see '>>>>>)  I attempting do determine if records exists in the TblsummaryQuartersFrozen, where the quarter = (i) and if true then proceed to process queries..

I have tried changing the variable type, single, string, variant, etc - no luck - What am I missing:

   
Dim ExtractDate As Date
Dim curDB As DAO.Database
Dim strSQL As String, strSQL1 As String
Dim nCt As Variant
Dim rs As DAO.Recordset, rs1 As DAO.Recordset
Dim i As Integer

 strSQL = "Select Year, FreezeQ1, FreezeQ2, FreezeQ3, FreezeQ4 from tblcurrent"

    Set rs = curDB.OpenRecordset(strSQL)
   For i = 1 To 4
">>>>>>        nCt = Nz(DCount("Quarter", "tblSummaryQuartersFrozen", "Quarter = " & i And "Year =" & Year(Date)))
           If rs.Fields("CountOfQuarter") > 0 Then
           
           ' If nCt = 0 Then
                GoTo cont:
            ElseIf rs.Fields("FreezeQ" & (i)) = -1 Then
                curDB.Execute ("DELETE *" & _
                               " FROM tblSummary" & _
                               " WHERE Quarter = " & i And "Year =" & Year(Date))
                curDB.Execute ("INSERT INTO tblSummary" & _
                               "Select *" & _
                               " FROM tblSummaryQuartersFrozen" & _
                               " WHERE Quarter = " & i And "Year =" & Year(Date))
                rs.MoveNext
            End If
     Next i
cont:

Open in new window

0
Comment
Question by:Karen Schaefer
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 26

Expert Comment

by:jerryb30
ID: 39869087
nCt = Nz(DCount("Quarter", "tblSummaryQuartersFrozen", "Quarter = " & i & " And Year =" & Year(Date)))
0
 
LVL 52

Expert Comment

by:Gustav Brock
ID: 39869891
As DCount returns 0 as a minimum, it should read:

Dim nCt As Long

nCt = DCount("*", "tblSummaryQuartersFrozen", "Quarter = " & i & " And Year = " & Year(Date) & "")

/gustav
0
 

Author Comment

by:Karen Schaefer
ID: 39870779
I have tried both suggestions and I am still getting the same error message.

Dim curDB As DAO.Database
Dim strSQL As String, strSQL1 As String
Dim nCt As Long
Dim rs As DAO.Recordset, rs1 As DAO.Recordset
Dim i As Integer

    strSQL = "Select Year, FreezeQ1, FreezeQ2, FreezeQ3, FreezeQ4 from tblcurrent"

    Set rs = curDB.OpenRecordset(strSQL)
'    strSQL1 = "SELECT Count(Quarter) AS CountOfQuarter, Quarter" & _
'                " FROM tblSummaryQuartersFrozen" & _
'                " WHERE (((Year) = Year(Date)))" & _
'                " GROUP BY Quarter" & _
'                " HAVING (((Quarter)='1')) OR (((Quarter)='2')) OR (((Quarter)='3')) OR (((Quarter)='4'))"
'     Set rs1 = curDB.OpenRecordset(strSQL1)
   For i = 1 To 4
  ' Dim nCt As Long
nCt = DCount("*", "tblSummaryQuartersFrozen", "Quarter = " & i & " And Year = " & Year(Date) & "")

    nCt = Nz(DCount("Quarter", "tblSummaryQuartersFrozen", "Quarter = " & i & " And Year =" & Year(Date)))
   '     nCt = Nz(DCount("*", "tblSummaryQuartersFrozen", "Quarter = " & i And "Year =" & Year(Date)))

Open in new window

0
Fill in the form and get your FREE NFR key NOW!

Veeam® is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

 

Author Comment

by:Karen Schaefer
ID: 39870847
still looking for help.
0
 
LVL 39

Accepted Solution

by:
PatHartman earned 2000 total points
ID: 39874612
You have used reserved names as column names and so you need to be diligent about enclosing all the mis-named columns in square brackets.  If you don't, you run the risk of the column name being interpreted as if it were the function.

In the future, try to avoid using reserved words as column names.  Access will warn you in some cases but perhaps not all.  The best way to be sure you are not running into any name that is already taken is to use compound words.  Such as SaleDate, ForecastYear, CompanyName.  These are more descriptive and you can be pretty sure that Access, Jet/ACE, and VBA haven't already squatted on them.
0
 

Author Closing Comment

by:Karen Schaefer
ID: 39875357
thanks for the input
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question