连接到Access数据库时Argument Not Optional错误

时间:2015-05-11 09:17:00

标签: ms-access vb6 adodb

我在vb6中使用这个简单的编码来连接到Access数据库,但每次编译此代码时都会显示错误:

  

参数不是可选的

并突出显示Private Sub Loginbtn_Click()txtUsrName

Private Sub Command1_Click()
    conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" _
    & "Data Source=E:\Ash\New folder (2)\login form.mdb;" _
    & "Persist Security Info=False"

    conn.Open

    Dim rs As New ADODB.Recordset

    rs.Open "SELECT * FROM table1 WHERE username = '" & txtUsrName & "'", conn, adOpenStatic, adLockReadOnly
    If rs.RecordCount <> 0 Then
        If txtPwd = rs!Password Then

            MsgBox "Username and Password Succesful!"
            'Remove msgbox above then call a form to be load if login is succesful!
            Call MDIForm1.Show
        Else
            MsgBox "Invalid Password, try again!", , "Login"
        End If
    Else
        MsgBox "Invalid Login, try again!", , "Login"

    End If
rs.Close
Set rs = Nothing
End Sub

1 个答案:

答案 0 :(得分:0)

我认为您只需要更改MsgBox命令:

MsgBox "Invalid Password, try again!", , "Login"

MsgBox "Invalid Password, try again!", "Login"