Results 1 to 2 of 2

Thread: VBA for Access

  1. #1
    Join Date
    Oct 2002
    Hartford, CT

    Question Unanswered: VBA for Access

    I have this piece of code to verify a user log in an access form.

    stUid = Pw_Count(txtUserID, txtPw)

    If stUid = 1 Then
    stDocName = "AAAAA"
    DoCmd.OpenForm stDocName, , , stLinkCriteria
    MsgBox ("Invalid password or user name")
    End If

    The pw_count function is written like this

    Function Pw_Count(inId As String, inPw As String)
    Dim SqlStr As String
    Dim StrId As String
    Dim StrPw As String
    Dim rst As DAO.Recordset

    StrId = inId
    StrPw = InPw
    SqlStr = "SELECT count(*) as uCount FROM users WHERE user_Name = StrId and password = StrPw"
    Set rst = CurrentDb.OpenRecordset(SqlStr, dbOpenDynaset)
    Pw_Count = rst!uCount
    Set rst = Nothing

    End Function

    I am getting a run time error (Too few parameters. Expected 2) after executing the function. And it returns nothing. When I step through the code, I notice that the SQL part may not be returing a value. I am thinking the count(*) is not working.

    Any Idea? anyone?


  2. #2
    Join Date
    Nov 2001

    stUid = NZ(DCount("UserID", "users", "user_Name = '" & txtUserID & "' and password = '" & txtPw & "'"),0)
    Function DCount replaces your function Pw_Count.

    Hope I didn't make any typos. UserID is a primary key of the table "users"


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts