This is an example of how I would generate the insert string:
Code:
Option Compare Database
Option Explicit
'The above lines should always be at the top of the code page
'Private Sub Something_Click()
Dim strSQL As String
Dim db As DAO.Database
Set db = CurrentDb()
' strSQL = "INSERT INTO Table1(Field1,Field2,Field3,Field4,Field5,Field6)"
strSQL = strSQL & " VALUES (#" & Now() & "#, '"
strSQL = strSQL & ConvertDbl(ConvertSngl([Forms]![Test]![Column1])) & "', '"
strSQL = strSQL & ConvertDbl(ConvertSngl([Forms]![Test]![Column2])) & "', '"
strSQL = strSQL & ConvertDbl(ConvertSngl([Forms]![Test]![Column3])) & "', '"
strSQL = strSQL & ConvertDbl(ConvertSngl([Forms]![Test]![Column4])) & "', '"
strSQL = strSQL & ConvertDbl(ConvertSngl([Forms]![Test]![Column5])) & "');"
'if this is code behind a form, I would use the following
' strSQL = "INSERT INTO Table1(Field1,Field2,Field3,Field4,Field5,Field6)"
' strSQL = strSQL & " VALUES (#" & Now() & "#, '"
' strSQL = strSQL & ConvertDbl(ConvertSngl(Me.[Column1])) & "', '"
' strSQL = strSQL & ConvertDbl(ConvertSngl(Me.[Column2])) & "', '"
' strSQL = strSQL & ConvertDbl(ConvertSngl(Me.[Column3])) & "', '"
' strSQL = strSQL & ConvertDbl(ConvertSngl(Me.[Column4])) & "', '"
' strSQL = strSQL & ConvertDbl(ConvertSngl(Me.[Column5])) & "');"
'for debugging purposes, comment out later
Debug.Print strSQL
db.Execute strSQL, dbFailOnError
'DoCmd.OpenQuery "QryTest1A", acNormal, acEdit
DoCmd.OpenQuery "QryTest2A", acNormal, acAdd
End Sub
'these two subs can be in a standard module or in the same code page as the code above
Code:
Function ConvertDbl(InputVal)
'removes double quotes
ConvertDbl = Replace(InputVal, """", "")
End Function
Function ConvertSngl(InputVal)
'replaced a single apostrophe with double apostrophes
ConvertSngl = Replace(InputVal, "'", "''")
End Function