Access Form Wizard Error?

Y

yachtfb

Private Sub Othercontacts_Click()
On Error GoTo Err_Othercontacts_Click

Dim stDocName As String
Hi there, can anyone help.

I have used the Control Wizard to create a button on a
form which opens a new form, but shows only records which
match a certain field.

Problem is that the wizard created code shows an error
that says there is a missing operator.

The code generated by the wizard is pasted below. I can't
find the error can you?

****************************

Dim stLinkCriteria As String

stDocName = "Contact Details"

stLinkCriteria = "[charityname]=" & Me![charityname]
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_Othercontacts_Click:
Exit Sub

Err_Othercontacts_Click:
MsgBox Err.Description
Resume Exit_Othercontacts_Click

End Sub

*****************************
 
S

Sandra Daigle

If CharityName is a text field then the search value needs to be wrapped in
quotes as follows:

stLinkCriteria = "[charityname]=""" & Me![charityname] & """"

There are three double quote characters (") before the first '&' nad four
after the second '&'.

When these are processed by VBA, the inside pair of quotation characters
will be converted to a single quotation character which is included in the
resulting string. The outside pair is always stripped off by VBA since they
are used as VBA's string delimiters.

I used the Wizard to create a similar field look-up and it included a
variation of the above string delimiting so it worked without modifications
for me. I'm using Access 2003 so perhaps in earlier versions this wizard
didn't take field datatype into account when building the criteria string.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top