我有以下设置:
我有一个带有未绑定文本框控件的表单。我有一个在每个AfterUpdate事件后触发的过程。
该过程将输入值发送到表,并将表中的值输入作为文本框的DefaultValue返回。该表通过表单和控件名称定义唯一行,即2个主键。
输入数据后,有一个按钮,以结构化的方式将表单中的数据发送到另一个表,并从报表中读取报表。数据以结构化方式输入到表中,并带有SQL查询。
问题是当用户在两个字段中输入超过2048个字符的文本时,代码会因限制而中断。由于表单的性质,表单上的两个字段在每个页面上可能会有超过2k个字符。
我的问题是,我可以规避,增加或绕过字符限制吗?
如果需要,我的代码将在下面发布以供参考(在表单的每个文本框中都加载了名为OptimizeS的过程):
将输入值写入表的过程:
Private Sub OptimizeS()
Dim cmd As ADODB.Command
Dim strForm As String
Dim strControl As String
Dim strSQL As String
Dim strCriteria As String
Set cmd = New ADODB.Command
cmd.ActiveConnection = CurrentProject.Connection
cmd.CommandType = adCmdText
strCriteria = "FormName = """ & Me.Name & """ " & _
"And ControlName = """ & Me.ActiveControl.Name & """"
' is there an existing default for this control?
If Not IsNull(DLookup("FormName", "Defaults", strCriteria)) Then
' if so then update row in table
strSQL = "UPDATE Defaults " & _
"SET DefaultVal = """ & Me.ActiveControl & """ " & _
"WHERE " & strCriteria
Else
' insert new row
strSQL = "INSERT INTO Defaults(" & _
"FormName,ControlName,DefaultVal) " & _
"VALUES(""" & Me.Name & """,""" & _
Me.ActiveControl.Name & """,""" & _
Me.ActiveControl & """)"
End If
cmd.CommandText = strSQL
cmd.Execute
End Sub
表单本身的支持程序:
1)
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim cmd As ADODB.Command
Dim strOpened As String
Dim strForm As String
Dim strSQL As String
Set cmd = New ADODB.Command
cmd.ActiveConnection = CurrentProject.Connection
cmd.CommandType = adCmdText
strOpened = "Opened = """ & Me.Name & """ "
If Not IsNull(DLookup("Opened", "AllOpened", strOpened)) Then
strSQL = "UPDATE AllOpened " & _
"SET Opened = """ & Me.Name & """ " & _
"WHERE " & strOpened
Else
strSQL = "INSERT INTO AllOpened(Opened) " & _
"VALUES(""" & Me.Name & """)"
End If
cmd.CommandText = strSQL
cmd.Execute
End Sub
2)
Private Sub Form_Open(Cancel As Integer)
Dim cmd As ADODB.Command
Dim strCriteria As String
Dim strOpened As String
Dim varDefault As Variant
Dim varOpened As Variant
Dim strForm As String
Dim strSQL As String
Dim ctrl As Control
Set cmd = New ADODB.Command
cmd.ActiveConnection = CurrentProject.Connection
cmd.CommandType = adCmdText
strOpened = "Opened = """ & Me.Name & """ "
varOpened = DLookup("Opened", "AllOpened", strOpened)
If IsNull(varOpened) Then
strSQL = "INSERT INTO AllOpened(Opened) " & _
"VALUES(""" & Me.Name & """)"
cmd.CommandText = strSQL
cmd.Execute
Else
GoTo ErrMsg
End If
For Each ctrl In Me.Controls
strCriteria = "FormName = """ & Me.Name & """ " & _
"And ControlName = """ & ctrl.Name & """"
varDefault = DLookup("DefaultVal", "Defaults", strCriteria)
If Not IsNull(varDefault) Then
ctrl.DefaultValue = """" & varDefault & """"
End If
Next ctrl
Exit Sub
ErrMsg:
MsgBox ("The form is already open by another user. Please double-check before editing."), , "Important!!!"
End Sub
3)
Private Sub Form_Unload(Cancel As Integer)
Dim strSQL As String
Dim strForm As String
Dim cmd As ADODB.Command
Set cmd = New ADODB.Command
cmd.ActiveConnection = CurrentProject.Connection
cmd.CommandType = adCmdText
strSQL = "DELETE FROM AllOpened " & _
"WHERE Opened = """ & Me.Name & """"
cmd.CommandText = strSQL
cmd.Execute
End Sub
答案 0 :(得分:0)
这是你上次评论的暗示。然后使用字符串变量尝试这个详细的代码,肯定没有2K的限制:
Dim DefaultString As String
DefaultString = Nz(varDefault)
ctrl.DefaultValue = DefaultString