I'm in the middle of creating a notepad application for Access - just to stay sharp. I've created the form for housing the Notepad and several buttons for varied functions. The notepad is saved to a table called tblContents as a Memo - this is because of the limit of 255 characters found with text.
I copied a large amount of text from SO and became aware of the apostrophe problem. You see when saving the text to the table I run a SQL statement which, when adding apostrophes, needs to be of a certain syntax (which I can't remember at this point) in order to run.
To maintain exactly what the user entered, apostrophes and all, is there a way to add this using the same SQL? I don't want to loop through the input and have it remove all the apostrophes.
Here's my code for adding what is input by the user:
'Save the memo
Public Sub SaveMemo()
'Examine the memo object
With Forms!frmNotepad!memo
'Set focus to memo in order to get length
.SetFocus
If Len(.Text) > 0 Then
'Save to table
Dim memoContents As String
memoContents = .Text
Dim strSQL As String
strSQL = "INSERT INTO tblContents (Contents)" & _
"VALUES ( '" & memoContents & "' ); "
'Set the database and execute the SQL
Dim db As Database
Set db = CurrentDb
db.Execute strSQL, dbFailOnError
Else
MsgBox ("Nothing to save!")
End If
End With
End Sub