Solved

Using Dcount in an IF statement

Posted on 2014-02-25
6
315 Views
Last Modified: 2014-03-06
Getting typemismatch when I am using

"              
        If Nz(DCount("RecordLock", "tblInvoice", "ContractNumber ='" & _
            gContractID & "'" And "RecordLock =" - 1)) > 0 Then
           
"

If gUser = "User" Then
                
        If Nz(DCount("RecordLock", "tblInvoice", "ContractNumber ='" & _
            gContractID & "'" And "RecordLock =" - 1)) > 0 Then
            
            Select Case MsgBox("Not Authorized to Print this report at this time, " _
                    & vbCrLf & "please see Manager or Systems Administrator." _
                    , vbOK Or vbCritical Or vbDefaultButton1, "Currently Not Available")
            
            Case vbOK
                Set rst = Me.RecordsetClone
                strCriteria = rs.Fields("RecordLock") = False
                rst.FindFirst strCriteria
                Me.Bookmark = rst.Bookmark
                Forms![frmCodingSlip]![LblPrintNote].Visible = True
            Case vbCancel
                DoCmd.RunCommand acCmdUndo
                Exit Sub
            End Select
        
        ElseIf Nz(DCount("RecordLock", "tblInvoice", "ContractNumber ='" & gContractID & "'" And "RecordLock = 0")) > 0 Then
   

Open in new window


What am I doing wrong?
0
Comment
Question by:Karen Schaefer
6 Comments
 
LVL 119

Assisted Solution

by:Rey Obrero
Rey Obrero earned 250 total points
Comment Utility
you don't need to use  Nz() in Dcount, dcount returns a number or 0

is ContractNumber DataType TEXT?

ElseIf DCount("RecordLock", "tblInvoice", "ContractNumber ='" & gContractID & "' And RecordLock = 0") > 0 Then

if NOT

ElseIf DCount("RecordLock", "tblInvoice", "ContractNumber =" & gContractID & " And RecordLock = 0") > 0 Then
0
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
Comment Utility
I'm guessing that your criteria is wrong. I assune that gContractID is probably numeric and should not be wrapped in singe qoutes.
0
 

Author Comment

by:Karen Schaefer
Comment Utility
No gcontracid is alpha numeric.

I decided to revert back to using a recordset.  Thanks for the input.
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 119

Expert Comment

by:Rey Obrero
Comment Utility
:-0 ?
0
 
LVL 49

Accepted Solution

by:
Gustav Brock earned 250 total points
Comment Utility
Your syntax is wrong, and Rey is right, no NZ here.
Thus:

If DCount("RecordLock", "tblInvoice", "ContractNumber ='" & _
            gContractID & "' And RecordLock = -1") > 0 Then

/gustav
0
 

Author Closing Comment

by:Karen Schaefer
Comment Utility
I decided to revert back to using a recordset.  Thanks for the input.  Points awarded for input.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.

762 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now