DCount with string (1 Viewer)

edojanssen

Registered User.
Local time
Today, 16:03
Joined
Jun 21, 2006
Messages
23
I'm trying to find out if a record exists. The data to be found will be entered by a InputBox and is numeric.

Code:
If DCount("*", "tblFakturen", "Faktuurnr = " & sInputE & "") <> 0 Then

gives typemismatch

Code:
If DCount("*", "tblFakturen", "Faktuurnr = '" & sInputE & "'") <> 0 Then

gives type doesn't match criteriaexpression

Who can help me out?

Edo
 

SOS

Registered Lunatic
Local time
Today, 07:03
Joined
Aug 27, 2008
Messages
3,514
Should be:

If DCount("*", "tblFakturen", "Faktuurnr = " & sInputE) <> 0 Then
 

edojanssen

Registered User.
Local time
Today, 16:03
Joined
Jun 21, 2006
Messages
23
Thanks SOS,

But your code gives "type doesn't match".

Code:
    Dim iJaarE As Integer
    Dim sJaarE As Integer
    Dim sInputE As String
    
InputBox:
    sInputE = InputBox("Geef het ErBo-boekstuknummer uit Exact op!", "ErBo-boekstuknummer")
    iJaarE = Format(Date, "yyyy")
    sJaarE = Right(CStr(iJaarE), 2)

    If sInputE Like sJaarE & "71*" Then
        If Len(sInputE) <> 8 Then
            GoTo InputBox
        Else
            If DCount("*", "tblFakturen", "Faktuurnr = " & sInputE) <> 0 Then
            'If DCount("*", "tblFakturen", [Faktuurnr] & " = '" & sInputE & "'") <> 0 Then
                MsgBox "Het ingevoerde boekstuknummer bestaat al", _
                "Kijk in Exact voor het juiste boekstuknummer"
                GoTo InputBox
            Else
                [Faktuurnr] = sInputE
                Me.ErBo.Value = True
                Me.Refresh
                DoCmd.GoToControl "Datum"
                GoTo NoErrorNummer
            End If
        End If
    Else
        GoTo InputBox
    End If
 

SOS

Registered Lunatic
Local time
Today, 07:03
Joined
Aug 27, 2008
Messages
3,514
Is Faktuurnr a number or text? If text you would need to use quotes:

If DCount("*", "tblFakturen", "Faktuurnr = " & Chr(34) & sInputE & Chr(34)) <> 0 Then
 

SOS

Registered Lunatic
Local time
Today, 07:03
Joined
Aug 27, 2008
Messages
3,514
Oh, and if it is NULL that could also cause a type mismatch problem. So, make sure that you don't have nulls there and if you do you will need to encapsulate the field with the NZ function.
 

Users who are viewing this thread

Top Bottom