Private sub Error

Hi all,

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




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
    Else
        DoCmd.RunMacro "macro_Z"
    End If
End Sub
PipMicAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jim Dettman (Microsoft MVP/ EE MVE)President / OwnerCommented:
Private Sub mcr_A_Click()

    If DCount("*", "Table1", "[txt] = " & chr$(34) & Forms![frmA]![Combo2]
 & Chr$(34)) > 0 Then
            MsgBox "Routine will be aborted, data to be appended already exists.", vbCritical
    Else
        DoCmd.RunMacro "macro_Z"
    End If

End Sub

 assuming combo2 is holding a string and that the form and control reference is correct, and that the form is open and available when the code executes.

Jim
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
PipMicAuthor Commented:
Thanks Jim, it worked...

May I ask why the need for chr$(34)?
0
PipMicAuthor Commented:
Thanks just figured it out .... many thanks again
0
Jim Dettman (Microsoft MVP/ EE MVE)President / OwnerCommented:
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:

"'
or

'"

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.

Jim.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.