运行时错误' 3061'参数很少。预计1 - 访问2013年

时间:2014-07-20 17:36:24

标签: vba access-vba ms-access-2010 ms-access-2013

行中的

/ *错误设置recSet1 = con1.OpenRecordset(sql,dbOpenDynaset,dbSeeChanges)* /

Dim con1 As DAO.Database
Dim recSet1 As DAO.Recordset
Dim sql As String

Set con1 = CurrentDb

txNIK.SetFocus
If txNIK.Text = "" Then
    MsgBox "Masukan NIK"
    err = True
End If
TxPas.SetFocus
If IsNumeric(TxPas) Then
    MsgBox "Format Salah"
    TxPas.SetFocus
    err = True
End If
TxPas.SetFocus

If Not err Then
    sql = "SELECT NIK, Pass FROM Tb_Peg WHERE NIK = txNIK "
    Set recSet1 = con1.OpenRecordset(sql, dbOpenDynaset, dbSeeChanges) 

/ *我应该写什么参数?错误3061 * /

    If recSet1.RecordCount > 0 Then
        'user does exist in database
        MsgBox "You can access the application"
    Else
        'user does not exist
        MsgBox "Your login details do not match"
    End If    'recordcount
    recSet1.Close
    con1.Close
    Set wk = Nothing
    Set con = Nothing
    Set recSet1 = "Nothing enter code here"
End If

/ *此代码用于访问2013 *中的验证登录?

1 个答案:

答案 0 :(得分:0)

您的SQL无法查看您的VBA参数。尝试这样的事情:

sql = "SELECT NIK, Pass FROM Tb_Peg WHERE NIK = '" & txNIK.Text & "'"

作为额外的预防措施,如果txNIK应该是一个数字(整数或长整数),我建议您明确声明变量:

Dim txNIK As Integer ' or Long

如果值是一个字符串(正如我在上面的查询建议中所假设的那样),那么您应该在查询中将值括在单引号中。