MS Access中将Text34值加入thisParcel表达式报3075运行错误求助
MS Access 运行时错误3075排查修复方案
运行时报3075属于Access的表达式/SQL语法错误,你代码中存在3处核心问题:
- 字符串拼接语法错误:VBA中跨行拼接表达式必须在行尾加
空格+下划线作为续行符,且字符串拼接推荐用&而非+,避免触发数值隐式转换报错。你当前thisParcel赋值语句行尾只有+,没有续行符,表达式直接断裂,导致thisParcel取值异常。 - INSERT语句单引号缺失:拼接
ParcelCode字段值的部分写为'" & thisParcel & " ,,thisParcel后缺少闭合单引号,直接导致SQL语法崩溃。 - 逻辑判断写法错误:
IsNull(Len(List0.Value))逻辑无效,Len()函数永远返回数值,不可能为Null,应该直接判断List0是否为空值。
修正后完整代码
Private Sub Command10_Click() Dim i As Long, w As Long Dim TrueOrFalse As Integer Dim thisParcel As String ' 关闭操作警告 DoCmd.SetWarnings False i = Val(Text2.Value) w = Val(Text34.Value) ' 修正判断顺序,优先判断空值避免报错 If IsNull(Text8) Or Text8 = "" Then TrueOrFalse = 0 Else TrueOrFalse = -1 End If ' 修正List0非空判断逻辑 If IsNull(List0.Value) Or List0.Value = "" Then MsgBox "请选择分配区域" DoCmd.SetWarnings True ' 退出前恢复警告 Exit Sub End If ' 增加续行符,统一用&做字符串拼接 thisParcel = List0.Value & Left("00000000", 8 - Len(Trim(Str(i)))) & Trim(Str(i)) & _ Left("00000", 5 - Len(Trim(Str(w)))) & Trim(Str(w)) ' 补全ParcelCode字段值的闭合单引号 DoCmd.RunSQL "INSERT INTO Schedule ( DiagramNo, OnGP, GPNo, ParcelCode, DiagramDeedNo ) VALUES ( '" & Text6.Value & "', " & TrueOrFalse & " , '" & Text8.Value & "' , '" & thisParcel & "' , '" & Text22 & "');" ' 操作完成后恢复警告 DoCmd.SetWarnings True End Sub
内容的提问来源于stack exchange,提问作者Zinhle
相关产品推荐
相关产品推荐

