Question : Apostrophe included in SQL Insert string

I'm sure someone has the perfect answer for this. what is the trick to inserting text into a table via sql/vba that includes apostrophe's? (Or other characters that will break it for that matter?)

For instance, I am using this code:
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
For j = 0 To 1
            
        'Save Row and Column Descriptions
        
        If j = 0 Then c = "Row" Else c = "Col"
        
        strSQL = "INSERT INTO tbHRI_Descrip (HRI_ID,Descrip_ID,DescripType,Label," & _
            "Description)" & _
            "VALUES ('" & Me.txtHRI_ID.Value & "','" & i & "','" & c & "','" & _
            Me.Controls("txt" & c & "Label" & i).Value & "','" & _
            Me.Controls("txt" & c & "Descrip" & i).Value & "')"
        
        DoCmd.RunSQL strSQL
              
        Next

Answer : Apostrophe included in SQL Insert string

you have to duplicate the quote. assuming that only Lable is subject to contain a quote:

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
For j = 0 To 1
            
        'Save Row and Column Descriptions
        
        If j = 0 Then c = "Row" Else c = "Col"
        
        strSQL = "INSERT INTO tbHRI_Descrip (HRI_ID,Descrip_ID,DescripType,Label," & _
            "Description)" & _
            "VALUES ('" & Me.txtHRI_ID.Value & "','" & i & "','" & c & "','" & _
            Me.Controls("txt" & c & "Label" & i).Value & "','" & _
            replace(Me.Controls("txt" & c & "Descrip" & i).Value , "'", "''") & "')"
        
        DoCmd.RunSQL strSQL
              
        Next
Random Solutions  
 
programming4us programming4us