VB保存的时候显示“无效使用null”
用的是VB6+ADO+ACCESS 2007,按钮代码如下:系统编译成功,但是,如图,当我数据库“加油信息”表中有“宏达”的信息时候,再加油保存,可以成功,但是,如果没有像“天顺”的信息的时候,点击此按钮保存,会弹出无效使用null的提示
Private Sub XPButton2_Click()
On Error GoTo finish
Dim sr, sr1 As String
Dim ye1, ye2, ye3 As Double
sr = "select 单位名称,预存款余额 from 客户信息 where 单位名称='" & Grid1.Cell(1, 1).Text & "'"
Set mdbrs1 = mdbconn.Execute(sr)
Set mdbrs2 = mdbconn.Execute("select sum(单次加油金额) from 加油信息 where 单位名称='" & Grid1.Cell(1, 1).Text & "'")
If mdbrs1.EOF = True Then
MsgBox "此单位不存在!!"
Else
If Grid1.Cell(1, 1).Text <> "" And Grid1.Cell(1, 2).Text <> "" And Grid1.Cell(1, 3).Text <> "" And Grid1.Cell(1, 4).Text <> "" And Grid1.Cell(1, 5).Text <> "" And Grid1.Cell(1, 6).Text <> "" And Grid1.Cell(1, 7).Text <> "" Then
Else
MsgBox "都不可以是空格!", vbInformation, "错误提示"
Exit Sub
End If
ye1 = mdbrs1.Fields(1)
ye2 = Val(Grid1.Cell(1, 6).Text)
ye3 = mdbrs2.Fields(0)
ye1 = ye1 - ye2 - ye3
sr1 = Grid1.Cell(1, 1).Text
'MsgBox "你当前的余额为:" & Int(ye1)
If ye1 < 200 And ye1 > 0 Then
MsgBox "你当前的余额为:" & Int(ye1) & "你的帐户余额不足200元,请及时预交!!", vbInformation, "错误提示"
End If
If ye1 < 0 Then
MsgBox "你的帐户已透支!透支金额为: " & Abs(Int(ye1)) & " 请及时预交!!", vbInformation, "透支提示"
'Exit Sub
End If
' If mdbrs1.Fields(1) > 200 Then
' If ye1 > 0 Then
If Grid1.Cell(1, 1).Text <> "" And Grid1.Cell(1, 2).Text <> "" And Grid1.Cell(1, 3).Text <> "" And Grid1.Cell(1, 4).Text <> "" And Grid1.Cell(1, 5).Text <> "" And Grid1.Cell(1, 6).Text <> "" And Grid1.Cell(1, 7).Text <> "" Then
'Set mdbrs1 = mdbconn.Execute("update 客户信息 set 预存款余额=ye1 where 单位名称='" & sr1 & "'")
Set mdbrs = mdbconn.Execute("insert into 加油信息 values('" & Grid1.Cell(1, 1).Text & "','" & str & "','" & Grid1.Cell(1, 3).Text & "',val('" & Grid1.Cell(1, 4).Text & "'),val('" & Grid1.Cell(1, 5).Text & "'),val('" & Grid1.Cell(1, 6).Text & "'),'" & Grid1.Cell(1, 7).Text & "')")
MsgBox "提交成功!", vbInformation, "提示"
Call XPButton1_Click
Else
MsgBox "都不可以是空格!", vbInformation, "错误提示"
End If
'Else
'MsgBox "你的帐户余额不足200元,操作无法继续,请及时预交!!", vbInformation, "错误提示"
Exit Sub
'End If
End If
Exit Sub
finish:
MsgBox Err.Description
End Sub VB 数据库 access
[解决办法]
暂时把 On Error 语句注释掉,调试运行,看错在哪一个语句。
[解决办法]
在问题解决之前,不要加On Error
[解决办法]
ye3 = Val(mdbrs2.Fields(0) & "")