Solved

DCount mismatch criteria error

Posted on 2010-09-01
3
501 Views
Last Modified: 2013-11-28
Hello,

I have a form with a tab control and two subforms inside separate tabs. The subforms save data into two different tables. The data outside the subform saves data to a third table.

I am using DCount code so that it checks whether the last subform has been filled before the form unloads. If the surveyid (primary key) from the main form is found in the subform's table, then it should allow the form to unload. If there is no match in the table, the form should not unload.

The code below executes correctly when there are no rows in the table, but when it finds matching rows in the table I get the error "Data type mismatch in criteria expression".  Is there something wrong with my code?

Private Sub form_unload(Cancel As Integer)
    If IsNull(Me.Surveyid) Then Exit Sub

    If DCount("*", "DeathTable", "surveyid = " & Me.Surveyid) > 0 Then
    Cancel = 0
    Exit Sub
    Else
    If DCount("*", "DeathTable", "surveyid = " & Me.Surveyid) = 0 Then
        MsgBox "Missing record in Death Table!"
        Cancel = 1
        Exit Sub
        Else
        Cancel = 0
    End If
    End If
   
End Sub
0
Comment
Question by:ghaphis
  • 2
3 Comments
 
LVL 75
ID: 33582986
Is Surveyid  Text or Numeric?  IF ... Text then try

If DCount("*", "DeathTable", "surveyid = " & &chr(34) & Me.Surveyid & Chr(34) ) > 0

mx
0
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 500 total points
ID: 33582993
surveyId could be Text data type

Private Sub form_unload(Cancel As Integer)
    If IsNull(Me.Surveyid) Then Exit Sub

    If DCount("*", "DeathTable", "surveyid = '" & Me.Surveyid &"'") > 0 Then
    Cancel = 0
    Exit Sub
    Else
    If DCount("*", "DeathTable", "surveyid = '" & Me.Surveyid & "'") = 0 Then
        MsgBox "Missing record in Death Table!"
        Cancel = 1
        Exit Sub
        Else
        Cancel = 0
    End If
    End If
   
End Sub



take note that your dcount on two lines are the same..


0
 
LVL 75
ID: 33583009
typo ... extra &

If DCount("*", "DeathTable", "surveyid = " &  chr(34) & Me.Surveyid & Chr(34) ) > 0
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
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.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

809 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