why do I get an error

  • Thread starter Emergency Power
  • Start date
E

Emergency Power

When I put a note with an single quote (As in the Word {won't} on a short
note form and try to open the full note form, (2 forms used to expand the
note -Both forms are the same record in the same table) an error comes up.
As soon as I take off the single quote, the full note form open fine.
{Example Wont is fine but -Won't gives and error.} SEE BELOW
Private Sub Notes_DblClick(Cancel As Integer)
On Error GoTo Err_btnExpandNote_Click

Dim stDocName As String
Dim stLinkCriteria As String


DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70

stDocName = "frmAppointmentsNote"

stLinkCriteria = "Notes =" & "'" & Me.Notes & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_btnExpandNote_Click:
Exit Sub

Err_btnExpandNote_Click:
MsgBox Err.Description
Resume Exit_btnExpandNote_Click

End Sub
 
T

tkelley via AccessMonster.com

Try this:

stLinkCriteria = "Notes =" & Chr(34) & Me.Notes & Chr(34)
 
J

John W. Vinson

When I put a note with an single quote (As in the Word {won't} on a short
note form and try to open the full note form, (2 forms used to expand the
note -Both forms are the same record in the same table) an error comes up.
As soon as I take off the single quote, the full note form open fine.
{Example Wont is fine but -Won't gives and error.} SEE BELOW

The problem is that the apostrophe in Won't is being seen as the closing quote
of the single-quote delimited string. If your notes will never contain
doublequote " characters use:

stLinkCriteria = "Notes =" & """" & Me.Notes & """"

That's four doublequotes on either side - to insert a doublequote in a
doublequote delimited string you double the doublequote (how's THAT for
doubletalk!)

If it might be possible that your notes will contain both ' and " characters,
you can instead replace each ' in the criteria string with two consecutive '
characters:

stLinkCriteria = "Notes ='" & Replace(Me.Notes, "'", "''") & "'"

For readability, that's

stLinkCriteria = "Notes = ' " & Replace(Me.Notes, " ' ", " ' ' ") & " ' "
 

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