View Full Version : opening a form from a value


Amy35
06-10-2002, 06:53 AM
I have the below code on the double-click event. It works sometimes. The times it doesn't is when the ProblemDescription field (which is being used to match the record) has a quote in it. As an example, the problem description might read: I can't logon to the LAN. The ' in can't causes a problem Or if someone puts "" in their problem description. Here's the error message: Syntax error (missing operator) in query expression '[ProblemDescription]='I can't logon to the LAN".
Anyone know how to fix this? Thanks in advance.

Amy

Private Sub ProblemDescription_DblClick(Cancel As Integer)
On Error GoTo Err_cmdFullView_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmOpenTickets"

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

Exit_cmdFullView_Click:
Exit Sub

Err_cmdFullView_Click:
MsgBox Err.Description
Resume Exit_cmdFullView_Click

End Sub

Fizzio
06-12-2002, 05:59 AM
Amy,

Is there no way you can use the ID of the record to filter the form rather than the text description? I'm assuming that each problem is recorded in a table and therefore is likely to have an unique ID. Failing that, another option is to strip all punctuation from the text description with a custom function before storing it in the table but this will make it confusing to read on a form / report.

HTH

Pat Hartman
06-12-2002, 08:14 AM
If a text field may contain embedded single quotes, you must surround it with double quotes in VBA.