按你的写法,用户名表中只有第一条记录是能用的,其他的都查不到。所以给你改了一下。
Private Sub Command0_Click()
If Text4 = "" Then
MsgBox "请填写用户名"
exit sub
ElseIf Text6 = "" Then
MsgBox "请填写密码"
exit sub
End If
Dim myUser As String
Dim mm As String
myUser= Me.Text4.Value
mm = Me.Text6.Value
if dcount("用户名","用户名","用户名 ='" & myUser& "'")=0 then
msgbox "无此用户名"
Me.Text4.Value = ""
exit sub
end if
if dlookup("密码","用户名","用户名 ='" & myUser & "'") <> mm then
msgbox "密码错误"
Me.Text6.Value = ""
end if
End Sub
另外,你的第2个问题,楼下已有正解
sql = "select * from 用户名 where 用户名 ='" & Me.Text4.Value & "'"