Link to home
Start Free TrialLog in
Avatar of PipMic
PipMicFlag for Gibraltar

asked on

Private sub Error

Hi all,

I have the following code in A97 but I am getting a error 3075.Grateful if someone can debug.

Private Sub mcr_A_Click()
Dim dtext As String

    dtext = Forms![frmA]![Combo2]
    If DCount("*", "Table1", "[txt] = " & dtext) > 0 Then
            MsgBox "Routine will be aborted, data to be appended already exists.", vbCritical
        DoCmd.RunMacro "macro_Z"
    End If
End Sub
Avatar of Jim Dettman (EE MVE)
Jim Dettman (EE MVE)
Flag of United States of America image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of PipMic


Thanks Jim, it worked...

May I ask why the need for chr$(34)?
Avatar of PipMic


Thanks just figured it out .... many thanks again
When you're giving a string value, it must be delimited either with " or '.  Many would write that statement like this:

DCount("*", "Table1", "[txt] = '" & Forms![frmA]![Combo2] & "'")

The result of the last argument when parsed by Access is:

 [txt] = 'some value'

You also could use a quote ("), but then you need to double it all up:

DCount("*", "Table1", "[txt] = "" & Forms![frmA]![Combo2] & """)

(and I may not have that quite right, but suffice to say using " inside of a string argument is just a pain).

But even if you just use ',  depending on the font and size your using, that can be difficult to read and tell if you have:



Chr$(34) gives you a quote ("), without using the quote character, so it's a lot easier to read and a lot more obvious exactly what it is your doing.