大家好!求教一个很简单的问题,登录问题,我做了一个程序,里面有个登录的界面。可是那代码老是不行,特向大家请教,大家帮忙看看,出错提示“with或对象变量未设置!“,代码如下:
Private Sub Command1_Click()
On Error GoTo A1
With Adodc1.Recordset
.Find "[用户名称] ='" & txtUserName & "' and [用户密码]='" & txtPassword & "'"
If .EOF Then
MsgBox "用户名或密码错误,登录失败! ", vbExclamation, "信息"
txtUserName.SetFocus
Exit Sub
Else
frmmain.Show
Me.Hide
End If
End With
Exit Sub
A1:
MsgBox Err.Description
End Sub
大家帮我改改或是发经过运行的代码给我看看,小弟我给大家跪下啦!
Private Sub Command1_Click()
On Error GoTo A1
With Adodc1.Recordset
.Find "[用户名称] ='" & txtUserName & "' and [用户密码]='" & txtPassword & "'"
If .EOF Then
MsgBox "用户名或密码错误,登录失败! ", vbExclamation, "信息"
txtUserName.SetFocus
Exit Sub
Else
frmmain.Show
Me.Hide
End If
End With
Exit Sub
A1:
MsgBox Err.Description
End Sub
大家帮我改改或是发经过运行的代码给我看看,小弟我给大家跪下啦!
.Find "[用户名称] ='" & txtUserName & "' and [用户密码]='" & txtPassword & "'"
Find方法是不可以and的
Adodc1.RecordSource = "Select * From mLogin Where UserName = '" & Text1.Text & "' And PassWord = '" & Text2.Text & "'"
Adodc1.Refresh
If Adodc1.Recordset.BOF And Adodc1.Recordset.EOF Then
MsgBox "用户名或密码错,请重输!"
Text1.SetFocus
Else
MDIForm1.Show
Unload Me
End If
End SubPrivate Sub Form_Load()
Adodc1.Visible = False
Adodc1.ConnectionString = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Password=;Initial Catalog=Test;Data Source=Server"
Adodc1.ConnectionTimeout = 0
Adodc1.CommandType = adCmdText
Adodc1.CursorLocation = adUseClient
Adodc1.CursorType = adOpenStatic
Adodc1.LockType = adLockOptimistic
End Sub