null不能赋值给字符串类型,也不能强制转换。用isNull()函数判断一下,赋给变量一个别的值。
如:if isNull(dataStudent.Recordset.fields(0)) then
s=""
else
s= isNull(dataStudent.Recordset.fields(0))
end if
下面两个等号的一行什么意思,估计也是错误的吧。
追问怎么改?
追答。。。。
if isNull(dataStudent.Recordset.fields(0)) then
s=0
else
s= isNull(dataStudent.Recordset.fields(0))
end if
DataStudent.Recordset.AddNew
DataStudent.Recordset!会员号字段名=val(s)+1 ' 这个过程中没见有添加到数据库
DataStudent.Recordset.Update
TxtId=text=Ltrim(str(s+1)) '这句估计没问题,不过没看懂意图。
CmdOk.Enabled=true
。。。
这段估计添加数值递增的系列号。表字段最好禁止允许Null。假如允许Null,那表示该学号注销了,记录集应该查询含有NUll 的字段,把学号填充到该字段好,而学号其实正好与记录指针位置一致的,所以只要把当前记录位置(DataStudent.Recordset.AbsolutePosition)赋给学号字段好了。
如果没有NUll字段的记录,那才Addnew来添加新的记录。
没办法,几句话说不清,你可以把工程发过来看看,邮件:[email protected]
追问已经发了
追答TxtId=text=Ltrim(str(s+1)) 改为:txtId.Text = Val(s) + 1
'这个确定按钮的事件过程修改一下
Private Sub cmdOK_Click()
Dim num, name As String
num = LTrim(RTrim(txtNumber.Text))
name = LTrim(RTrim(txtName.Text))
If Len(num) <> 8 Or IsNumeric(num) = False Then
MsgBox "学号输入有误,请输入8位数", vbOKOnly + vbInformation, "提示"
txtNumber.SetFocus
Else
If Len(name) = 0 Then
MsgBox "姓名不能为空,请重输!", vbOKOnly + vbInformation, "提示"
Else
With dataStudent.Recordset '没有写数据,所以会产生空记录
!stuID = txtId
!stuNumber = txtNumber
!stuName = txtName
.Update
End With
'dataStudent.Recordset.Update
'dataStudent.Refresh
cmdOK.Enabled = False
Call changeEnabled(False) '编辑完毕
End If
End If
End Sub