PC Review


Reply
Thread Tools Rate Thread

ADO Access Query bombs when data has apostrophe

 
 
=?Utf-8?B?S2VuIFZhbGVudGk=?=
Guest
Posts: n/a
 
      1st May 2007
This code works, but when EmployeeName has an appostophe , rs.open bombs.
(ADO seems to use an apostrophen instead of quotes to deliniate text)
Is there a workaround?

Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset

Sub TestADO(EmployeeName As String)
Set cn = New ADODB.Connection
cn.Open "Driver={Microsoft Access Driver (*.mdb)};Dbq=" & DBaseName &
";Uid=Admin;Pwd=;"
Set rs = New ADODB.Recordset
rs.Open "SELECT * FROM YTD_Data WHERE ProjectManager='" & EmployeeName &
"';", cn, adOpenDynamic, adLockOptimistic, adCmdText
rs.Close
Set rs = Nothing
cn.Close
Set cn = Nothing
End Sub
 
Reply With Quote
 
 
 
 
=?Utf-8?B?VmVyZ2VsIEFkcmlhbm8=?=
Guest
Posts: n/a
 
      1st May 2007
Ken,

try:

rs.Open "SELECT * FROM YTD_Data WHERE ProjectManager='" &
Replace(EmployeeName, "'", "''") & "';", cn, adOpenDynamic, adLockOptimistic,
adCmdText



--
Hope that helps.

Vergel Adriano


"Ken Valenti" wrote:

> This code works, but when EmployeeName has an appostophe , rs.open bombs.
> (ADO seems to use an apostrophen instead of quotes to deliniate text)
> Is there a workaround?
>
> Dim cn As ADODB.Connection
> Dim rs As ADODB.Recordset
>
> Sub TestADO(EmployeeName As String)
> Set cn = New ADODB.Connection
> cn.Open "Driver={Microsoft Access Driver (*.mdb)};Dbq=" & DBaseName &
> ";Uid=Admin;Pwd=;"
> Set rs = New ADODB.Recordset
> rs.Open "SELECT * FROM YTD_Data WHERE ProjectManager='" & EmployeeName &
> "';", cn, adOpenDynamic, adLockOptimistic, adCmdText
> rs.Close
> Set rs = Nothing
> cn.Close
> Set cn = Nothing
> End Sub

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Access 2007 Macro bombs when run with Access 2003 Del Microsoft Access Forms 1 19th Oct 2009 06:53 PM
Access bombs MarianneZ Microsoft Access 5 12th Dec 2008 06:29 PM
Union All Query bombs report scott Microsoft Access Queries 2 6th Feb 2008 01:45 AM
Access bombs out on form/report/query update... =?Utf-8?B?UG9vZGxlSGVhZA==?= Microsoft Access 2 15th Nov 2005 04:05 PM
addition of apostrophe in data in excel after access export =?Utf-8?B?R2l6?= Microsoft Access External Data 5 5th Sep 2005 06:50 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:39 AM.