VB新手求助
Private Sub Command1_Click()Dim pl, n As String
pl = 1
n = 4
Dim sqlStr As String
Dim sqlpre As String
Dim rst As New ADODB.Recordset
Dim pre As New ADODB.Recordset
If Trim(Text1.Text) <> "" And Trim(Text2.Text) <> "" Then
sqlpre = "Select 员工工号 from 员工登录信息表 where 员工工号= ' " & Text1.Text & " ' "
sqlStr = "Select * from 员工登录信息表 where 员工工号= ' " & Text1.Text & " ' and 密码= ' " & Text2.Text & " ' "
Set pre = connstr(sqlpre)Set rst = connstr(sqlStr)
If pre.RecordCount > 0 Then
If rst.RecordCount > 0 Then
MsgBox "登录成功!"
Unload Me: Form5.Show
Else
b = MsgBox("密码不正确,是否重新登录?,你还剩" + n + "次机会!", vbOKCancel, "为保证系统安全,您一共有5次机会!")
If b = vbOK Then
Text2.SetFocus
pl = pl + 1
n = 5 - pl
If pl = 5 Then
End
End If
Else
Form4.Hide
form1.Show
End If
End If
Else
MsgBox "该用户不存在或用户名不正确!"
End If
Else
a = MsgBox("用户名或密码不能为空!", vbOKCancel, "输入提示框!")
If a = vbOK Then
Text1.SetFocus
Else
Form4.Hide
form1.Show
End If
End If
End Sub
调试提示,pre=<调试变量或with块变量未设置>,请问如何修改?
这是一个链接数据库的用户登录系统 connstr是自定义函数么?这个错误看上去是连数据库都没连上 是自定义函数,按书上来的,功能是用recordset对象执行SQL命令。按您看有没有必要使用呢?还有那个数据库要怎么连上呢 上connstr 的代码 Public Function connstr(ByVal str As Long) As ADODB.Recordset
Dim con As ADODB.Connection
Dim rst As ADODB.Recordset
Set con = New ADODB.Connection
Set rst = New ADODB.Recordset
con.Open "dsn=student"
rst.Open str, con, adOpenStatic, adLockOptimistic
Set connstr = rst
End Function
student 是自己添加的数据源 con.Open "dsn=student"
这个错了
你去www.connectionstrings.com上面查你需要的connection string的格式,然后照着改 http://download.csdn.net/detail/veron_04/3827200
补充:VB , 数据库(包含打印,安装,报表)