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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to get around special characters??? 3

Status
Not open for further replies.

steve728

Programmer
Mar 16, 2003
536
US
I'm having a problem updating the storage.memo field with the contents of Forms![Storage Data Entry]!TxtMemo) because of special chars within it (i.e. ##, ' + *, etc.) Please help me solve this issue.

If .TxtPurse.Value > Me.TxtPrior Then
strMemo = "-" & Now() & " Increased pocket from $" & .TxtPrior.Value & " to " _
& .TxtPurse.Value & vbCrLf & Nz(Trim(Forms![Storage Data Entry]!TxtMemo), " ")
Else
strMemo = "-" & Now() & " Decreased pocket from $" & .TxtPrior.Value & " to " _
& .TxtPurse.Value & vbCrLf & Nz(Trim(Forms![Storage Data Entry]!TxtMemo), " ")
'Replace(strMemo, "'", "''")
End If
adoconnection.Execute "UPDATE storage SET purse = " & .TxtPurse.Value _
& ", storage.memo = '" & strMemo & "' WHERE Trim(unitnum) = '" & Trim(.TxtUNITNUM.Value) & "';", , 129
 
The only characters you might have trouble with are quotes (double or single). The way to escape them is to double them up, example:

strMemo = "''cake'' say I"

The other characters you mentioned you shouldn't have a problem with.

 
This is great but please insert the corrections into my code so that I can see where to and how to apply this. Please.

 
How about you insert the code, steve728, and we correct any mistakes? I notice that you have commented out the replace statement that was designed to do just what JoeAtWork says.
 
If it's Access, create a parameter query
If it's SQL, create a stored procedure
Use the Command object and Parameters.

Set cmd = New ADODB.Command
With cmd
.ActiveConnection=adoConnection
.CommandText="NameOfQuery"
.ComandType=adStoredProc
.Parameters.Refresh
.Parameters("@unitNum")=Trim(unitnum)
.Parameters("@Memo")=Forms![Storage Data Entry]!TxtMemo
.Execute
End With

No problem with any special characters anymore.

HTH

[pipe]
Daniel Vlas
Systems Consultant

 
I'm using Access 2002 so here goes:

.TxtPurse.Value > Me.TxtPrior Then
strMemo = "-" & Now() & " Increased pocket from $" & .TxtPrior.Value & " to " _
& .TxtPurse.Value & vbCrLf & Nz(Trim(Forms![Storage Data Entry]!TxtMemo), " ")


adoconnection.Execute "UPDATE storage SET purse = " & .TxtPurse.Value _
& ", storage.memo = '" & Replace(strMemo, "'", "''")
& "' WHERE Trim(unitnum) = '" & Trim(.TxtUNITNUM.Value) & "';", , 129
 
The parameter query should be something like:

PARAMETERS [@purse] Text, [@memo] Text, [@unitnum] Text ( 255 );
UPDATE storage SET purse = [@purse], storage.memo = [@memo]
WHERE trim(unitnum)=[@unitnum;

Save it to the database.

Then, instead of your 'adoconnection.execute' line, insert:

Dim cmd As New ADODB.Command
Set cmd = New ADODB.Command
With cmd
.ActiveConnection=adoConnection
.CommandText="NameOfQueryAsYouSavedIt"
.ComandType=adStoredProc
.Parameters.Refresh
.Parameters("@unitNum")=Trim(unitnum)
.Parameters("@purse")=Me.TxtPurse 'overlooked this one last time
.Parameters("@memo")=Forms![Storage Data Entry]!TxtMemo
.Execute
End With

That should do.


[pipe]
Daniel Vlas
Systems Consultant

 
I've given you all stars for sharing your weekends with me. I Don't know what I would do whithout all my cyber friends out there. Probably punt.

Steve728
 
Also take a look at the Replace() method.

Ian Mayor (UK)
Program Error
Your lack of planning is not my emergency!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top