当保存记录时,没有出错提示,就是不能保存到表中。
保存代码如下:
Private Sub 保存记录_Click()
On Error GoTo Err_保存记录_Click
'定义各种变量
Dim STemp As String
Dim Rs As ADODB.Recordset
Set Rs = New ADODB.Recordset
STemp = "Select * From 能耗统计"
'为打开数据表"查询语句"字符变量赋值
Rs.Open STemp, CurrentProject.Connection, adOpenKeyset, adLockOptimistic
'判断必填文本框和组合框是否为空
If IsNull(Me![id]) = True Then
MsgBox "请输入日期,它不能为空!", vbOKOnly, "输入id"
Me![id].SetFocus
ElseIf IsNull(Me![日期]) = True Then
MsgBox "请输入日期,它不能为空!", vbOKOnly, "输入日期"
Me![日期].SetFocus
ElseIf IsNull(Me![班次]) = True Then
MsgBox "请输入班次,它不能为空!", vbOKOnly, "输入班次"
Me![班次].SetFocus
ElseIf IsNull(Me![统计员]) = True Then
MsgBox "请输入统计员,它不能为空!", vbOKOnly, "输入统计员"
Me![统计员].SetFocus
Else
'保存能耗输入
STemp = "INSERT INTO 能耗统计"
STemp = STemp & "(ID,日期,班次,浊环水,净环水,自来水,自来水1,水抄表人,[1#动力变],[2#动力变],[1#整流变],[2#整流变],[3#整流变],[4#整流变],[5#整流变],[高压电机],电抄表人,煤,统计员,备注)"
STemp = STemp & "VALUES ('" & Me![日期] & "',"
STemp = STemp & "'" & Me![班次] & "','" & Me![浊环水] & "',"
STemp = STemp & "'" & Me![净环水] & "','" & Me![自来水] & "',"
STemp = STemp & "'" & Me![自来水1] & "','" & Me![水抄表人] & "',"
STemp = STemp & "'" & Me![1#动力变] & "','" & Me![2#动力变] & "',"
STemp = STemp & "'" & Me![1#整流变] & "','" & Me![2#整流变] & "',"
STemp = STemp & "'" & Me![3#整流变] & "','" & Me![4#整流变] & "',"
STemp = STemp & "'" & Me![5#整流变] & "','" & Me![高压电机] & "',"
STemp = STemp & "'" & Me![电抄表人] & "','" & Me![煤] & "',"
STemp = STemp & "'" & Me![统计员] & "','" & Me![备注] & "')"
'刷新子窗体
Me![能耗输入子窗体].Requery
End If
Exit_保存记录_Click:
Exit Sub
Err_保存记录_Click:
MsgBox err.Description
Resume Exit_保存记录_Click
End Sub
[此贴子已经被作者于2007-3-12 12:00:33编辑过]
|