Dim cn As ADODB.Connection
Dim rx As New ADODB.Recordset
'user_online = 1
Set cn = GetNewConnection
'On Error GoTo Err_Command6_Click
If IsNull(Text2) Or IsNull(Text4) Then
MsgBox "没有输入用户名或密码,请重新输入", vbInformation, "系统提示"
Exit Sub
End If
rx.Open "select * from user_tbl where [user_id]='Me.Text2.Value' and [user_password]='Me.Text4.Value'"
'连接函数
Public Function GetNewConnection() As ADODB.Connection
Dim oCn As New ADODB.Connection
Dim sCnStr As String
看了书上的很多资料改来改去都没有效果作者: dreamice01 时间: 2008-2-4 11:27 标题: 回复 6# 的帖子 公司内网上不了,只能上MSN作者: dreamice01 时间: 2008-2-4 11:28 dreamice01@hotmail.com作者: dreamice01 时间: 2008-2-4 11:37 标题: 回复 9# 的帖子 像这种问题,有其它解决办法吗?作者: dreamice01 时间: 2008-2-4 14:05 标题: 回复 9# 的帖子 '连接数据库的函数
Public Function GetNewConnection() As ADODB.Connection
Dim oCn As New ADODB.Connection
Dim sCnStr As String
sCnStr = "Provider='sqloledb';Data Source='wangqiang';" & _
"Initial Catalog='accesstata';Integrated Security='SSPI';user_id='sa';password='120979120979'"
oCn.Open sCnStr
If oCn.State = adStateOpen Then
Set GetNewConnection = oCn
End If
End Function
'登录按钮代码
Private Sub Command6_Click()
Dim cn As ADODB.Connection
Dim rx As ADODB.Recordset
user_online = 1
Set cn = GetNewConnection
If IsNull(Text2) Or IsNull(Text4) Then
MsgBox "没有输入用户名或密码,请重新输入", vbInformation, "系统提示"
Exit Sub
End If
rx.Open "select * from user_tbl where [user_name]='" & Text2 & " ' and [user_password]=' " & Text4 & "'", cn, adOpenKeyset, adLockBatchOptimistic
If rx.EOF Then
MsgBox "你输入的用户名或密码错误,请重新输入!" & Chr(10) & Chr(13) & "如果您还没有注册,请点击注册按钮!", vbCritical, "系统提示"
Me.Text2.Value = ""
Me.Text4.Value = ""
Me.Text2.SetFocus
Exit Sub
Else
user_name = Me.Text2.Value
user_id = rx(user_id)
user_level = rx(user_level)
user_online = 2
DoCmd.Close
DoCmd.OpenForm "网络留言簿系统", acNormal
End If
rx.Close
Set rx = Nothing
End Sub
我的后台数据库是SQL SEVER 2000
上午试了一上午,在接近中午的时候没有问题,但一冲动就忘记保存代码了,下午一写,又提示出错了,这次的提示是:对象变量或WITH块变量未设置
晕倒了