对丰富文本使用INSERT INTO

时间:2018-09-18 18:35:27

标签: sql access-vba ms-access-2016

我有一个带有RTF框的表格和一个带有RTF字段的表格。我正在尝试使用INSERT INTO将表格中的文本复制到表格中。除了富文本文件之外,我所有的字段都很好用。我不确定如何格式化INSERT INTO字符串。这是我尝试过的。

DIM RT as String
RT = Me.RTBox
StrSQL = "INSERT INTO MyTbl (RTField) VALUES (""" & RT & """);" 'Tried triple quotes
StrSQL = "INSERT INTO MyTbl (RTField) VALUES ('" & RT & "');" 'Tried string quotes

似乎没有任何效果。请有人告诉我如何将变量括起来。我也要插入几个字段。日期,时间和其他非RTF字段。其他都很好。

3 个答案:

答案 0 :(得分:1)

RT = Me.RTBox

Sets the entire control to the RT variable You want just the value that is in the control, try

RT = Me.RTBox.Value

P.S. Consider using

Option Explicit

At the top of your modules to ensure type compatibility. Using this would catch the error when you compile your code.

答案 1 :(得分:1)

尝试使用 DAO

Dim rs As DAO.Recordset    
Dim RT As String

Set rs = CurrentDb.OpenRecordset("Select RTField From MyTbl")
RT = Me!RTBox.Value

rs.AddNew
    rs!RTField.Value = RT
    ' or simply:
    ' rs!RTField.Value = Me!RTBox.Value
rs.Update
rs.Close

答案 2 :(得分:-1)

这对您有用吗?

StrSQL = "INSERT INTO MyTbl (RTField) VALUES ('' & RT & '');"  -- Double Ticks for a single tick.