If .RecordCount = 0 Then .AddNew为什么对象关闭时 不允许操作
OptionExplicitPrivateSubCommand1_Click()DimstrNews,i%strNews=Array("考勤月份","姓名","编号","...
Option Explicit
Private Sub Command1_Click()
Dim strNews, i%
strNews = Array("考勤月份", "姓名", "编号", "缺勤次数")
For i = 0 To 3 '验证设定的工资标准
If Text1(i) = "" Then
MsgBox strNews(i) & "级工资标准不能为空,且必须为数字", _
vbCritical, "职务工资标准设定"
Text1(i).SetFocus
Text1(i).SelStart = 0
Text1(i).SelLength = Len(Text1(i))
Exit Sub
End If
Next
With Wage_Manage_Data.rsKaoWage
If .RecordCount = 0 Then .AddNew
.Fields("考勤月份") = Text1(0)
.Fields("姓名") = Text1(1)
.Fields("编号") = Text1(2)
.Fields("缺勤次数") = Text1(3)
.Update
End With
MsgBox "数据保存成功!", vbInformation, "考勤信息"
End Sub
Private Sub Command2_Click()
Unload Me
End Sub 展开
Private Sub Command1_Click()
Dim strNews, i%
strNews = Array("考勤月份", "姓名", "编号", "缺勤次数")
For i = 0 To 3 '验证设定的工资标准
If Text1(i) = "" Then
MsgBox strNews(i) & "级工资标准不能为空,且必须为数字", _
vbCritical, "职务工资标准设定"
Text1(i).SetFocus
Text1(i).SelStart = 0
Text1(i).SelLength = Len(Text1(i))
Exit Sub
End If
Next
With Wage_Manage_Data.rsKaoWage
If .RecordCount = 0 Then .AddNew
.Fields("考勤月份") = Text1(0)
.Fields("姓名") = Text1(1)
.Fields("编号") = Text1(2)
.Fields("缺勤次数") = Text1(3)
.Update
End With
MsgBox "数据保存成功!", vbInformation, "考勤信息"
End Sub
Private Sub Command2_Click()
Unload Me
End Sub 展开
1个回答
展开全部
这个错误我碰到的都是,程序在其他地方把数据库的连接关闭了,或者,没有把一个记录集赋值给recordset对象,或者recordset对象被关闭。在代码里没看到数据库连接的语句,是不是放在其他地方了,检查一下。
没使用过楼主读取数据库的方法,我一般是这样的
Public mycon As New ADODB.Connection
Public mycom As New ADODB.Command
Public myrec As New ADODB.Recordset
Public mysql As String
constr = "连接字符串"
mycon.Open constr
'这之前的都放在模块里,在程序开始执行一次,打开数据库。
'执行SQL用了两种方法
Set mycom.ActiveConnection = mycon
dim str as string
str ="SQL语句"
mycom.CommandText = str
Set myrec = mycom.Execute
'上面这是一般的这几句写成个过程,哪用了哪调,传个SQL语句就OK
'下面这个是有时候要数据分页的
mysql = ""
myrec.CursorLocation = adUseClient '设置游标类型为客户端
myrec.Open mysql, mycon, adOpenStatic, adLockPessimistic '打开连接,并设置记录集类型为静态记录集,以便使用recordset的recordcount属性
myrec.pagesize = 12 '设置逻辑页的大小
这样写,不用老是打开关闭记录集,有时地方太多就忘记关闭了
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询