Solved

Using Dcount in an IF statement

Posted on 2014-02-25
6
344 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
[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 120

Assisted Solution

by:Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1) earned 250 total points
ID: 39887137
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 48

Expert Comment

by:Dale Fye (Access MVP)
ID: 39887154
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
ID: 39887165
No gcontracid is alpha numeric.

I decided to revert back to using a recordset.  Thanks for the input.
0
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!

 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 39887216
:-0 ?
0
 
LVL 50

Accepted Solution

by:
Gustav Brock earned 250 total points
ID: 39888072
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
ID: 39910068
I decided to revert back to using a recordset.  Thanks for the input.  Points awarded for input.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
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…

728 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