怎样向表中添加数据?谢谢!!
Dim str As String
Dim rs As New ADODB.Recordset
Dim curdb As Database
Dim action As Integer
.....
logname = Trim(Me.UserName)
pwd = Trim(Me.PassWord)
.....
str = "select * from users where 用户='" & logname & "' and 密码='" & pwd & "'"
Set rs = GetRS(str)
If rs.EOF Then
DoCmd.Beep
'若无此用户则插入
curdb.Execute "insert into users (用户,密码) values('" & logname & "','" & pwd & "')"
action = MsgBox("用户添加成功", vbOKOnly, "提示")
If action = 1 Then
DoCmd.Close acForm, "添加用户"
End If
end if
这是一段添加用户的程序片段,GetRS()是一个公共函数负责检索满足条件的记录。
若记录不存在则则将文本框中的内容添加在表中。可是运行时总提示“对象变量或
with块变量未设置" 我猜是curdb.Execute "insert into ...有问题,但不知
怎么该,请大家帮忙!谢谢!!