More apostrophes!!

A

Anthony Speiser

The following causes errors on my forms when the record contains an
apostrophe:

Private Sub Combo2_AfterUpdate()
' Find the record that matches the control.
Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "[ownername] = '" & Me![Combo2] & "'"
Me.Bookmark = rs.Bookmark
End Sub



what changes do i need to make?


tia
 
K

kingston via AccessMonster.com

Will your data contain double quotation marks? If not, try:

rs.FindFirst "[ownername] = """ & Me![Combo2] & """"



Anthony said:
The following causes errors on my forms when the record contains an
apostrophe:

Private Sub Combo2_AfterUpdate()
' Find the record that matches the control.
Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "[ownername] = '" & Me![Combo2] & "'"
Me.Bookmark = rs.Bookmark
End Sub

what changes do i need to make?

tia
 
A

Anthony Speiser

Thanks!!

did the trick


tony



kingston via AccessMonster.com said:
Will your data contain double quotation marks? If not, try:

rs.FindFirst "[ownername] = """ & Me![Combo2] & """"



Anthony said:
The following causes errors on my forms when the record contains an
apostrophe:

Private Sub Combo2_AfterUpdate()
' Find the record that matches the control.
Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "[ownername] = '" & Me![Combo2] & "'"
Me.Bookmark = rs.Bookmark
End Sub

what changes do i need to make?

tia
 
P

Powderfinger

I always get rid of single quotes in the database.

Private Sub ownername_AfterUpdate()
If Not IsNull(Me.ownername) Then
Me.ownername= Replace(Me.ownername, "'", "")
End If
End Sub

If you allow them then everytime you pass a filter into a form or report it
will bite you.
 
D

Douglas J. Steele

I suspect that that will lead to dissatisfied customers complaining that
their name shows up as OReilly, rather than O'Reilly.

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Powderfinger said:
I always get rid of single quotes in the database.

Private Sub ownername_AfterUpdate()
If Not IsNull(Me.ownername) Then
Me.ownername= Replace(Me.ownername, "'", "")
End If
End Sub

If you allow them then everytime you pass a filter into a form or report
it
will bite you.

Anthony Speiser said:
The following causes errors on my forms when the record contains an
apostrophe:

Private Sub Combo2_AfterUpdate()
' Find the record that matches the control.
Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "[ownername] = '" & Me![Combo2] & "'"
Me.Bookmark = rs.Bookmark
End Sub



what changes do i need to make?


tia
 
T

Tom Lake

Douglas J. Steele said:
I suspect that that will lead to dissatisfied customers complaining that
their name shows up as OReilly, rather than O'Reilly.

O'Really? 8^) You could replace the apostrophe with a left curly brace {
until it's
printed then replace the { with an apostrophe if it's that important.

Tom Lake
 
D

Douglas J. Steele

Tom Lake said:
O'Really? 8^) You could replace the apostrophe with a left curly brace
{ until it's
printed then replace the { with an apostrophe if it's that important.

Why not simply store the data correctly, and ensure that you handle the
apostrophes correctly in your queries?

I showed one approach in my May, 2004 "Access Answers" column in Pinnacle
Publication's "Smart Access". You can download the column (and sample
database) for free at http://www.accessmvp.com/DJSteele/SmartAccess.html
 

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

Similar Threads

Combo Box Error 3077 - Access 2003 1
Textbox Filter 4
Searching 3
Error 2147352567 2
RunTime Error 3070 8
Copy Record Button Function 1
access runtime error 3314 Me.Bookmark = rs.Bookmark 0
Error 2237 8

Top