Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help. Double quotes in text data 1

Status
Not open for further replies.

ACTHelp

MIS
Feb 8, 2005
30
0
0
US
I'm trying to write a quick vb app to help replace server names in .ppx files. ppx files are Cognos PowerPlay files. The contain the server name that the .ppx is suppose to run against. We are a big PowerPlay shop. I'd like to write an access app which will allow them to identify the files to be changed..and the old server name and new server name. I can open and read the .ppx but when i try to write it to a table or do anything else with it I have problems because the data has " in it.

For instance, the first couple lines of data in the file looks like this:
<?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?>
<Document xmlns=" <HEAD xmlns="

Here is the code I have right now:

Public Sub RunCurrentRequest()
On Error GoTo RunCurrentRequest_Err
Dim objwPApp As Object
Dim rst As ADODB.Recordset
Dim strSQL As String
Dim strMsg As String
Dim strfullname As String
Dim objFileSystem
Dim txt As Object ' or scripting.textstream
Dim strLine As String
Dim strtablename As String

Set rst = New ADODB.Recordset
Set objFileSystem = CreateObject"Scripting.FileSystemObject")
strSQL = "select * from [tblPPXFiles]"
rst.Open strSQL, CurrentProject.Connection
gstrPPxFilePath = rst("Path")
gstrppxFileName = rst("filename")

While Not rst.EOF
gstrPPxFilePath = rst("Path")
gstrppxFileName = rst("filename")
strtablename = rst("tableName")
strfullname = gstrPPxFilePath & "\" & gstrppxFileName
strSQL = "CREATE TABLE " & strtablename & " (Textfield TEXT)"
DoCmd.RunSQL strSQL


Set txt = objFileSystem.opentextfile(strfullname, 1) ' 1 - ForReading
Do While Not txt.atendofstream

strLine = txt.readline

strSQL = "INSERT INTO " & strtablename & "(Textfield) values ('" & replace(strline, "#"#","^") & "')"

DoCmd.RunSQL strSQL

Loop
txt.Close
Set txt = Nothing

If Err <> 0 Then
MsgBox "Unable to Open WordPad file -" & strfullname
End If
rst.MoveNext
Wend
 
I don't understand this:[tt]
strSQL = "INSERT INTO " & strtablename & "(Textfield) values ('" & replace(strline, "#"#","^") & "')"[/tt]
I'd use this instead:[tt]
strSQL = "INSERT INTO " & strtablename & "(Textfield) values ('" & Replace(strline, "'","''") & "')"[/tt]

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Oh dear - if PHV's suggestion doesn't work, then another suggestion is to read up on usage of the parameters collection ...

Here's a quick typed up version using ado (typed not tested)

[tt]dim cn as adodb.connection
dim cmd as adodb.command
dim prm as adodb.parameter
set cn = currentproject.connection
strSQL = "INSERT INTO " & strtablename & "(Textfield) values (?)"
set cmd = new adodb.command
with cmd
set .activeconnection = cn
.commandtext = strsql
.commandtype = adcmdtext
set prm = .createparameter("myparam", advarwchar,adparaminput, 255)
.parameters.append prm
prm.value = strline
.execute ,,adexecutenorecords
end with
set prm = nothing
set cmd = nothing
set cn = nothing[/tt]

Roy-Vidar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top