Recordset ignoring parameters

merkava

Registered User.
Local time
Today, 17:39
Joined
Oct 16, 2006
Messages
25
Hello All,

In the code below I am trying to pull a specific value from the DB but is appears to ignore the variable I am sending the RS.


Code:
Sub GetUserdetails()
Dim rs As DAO.Recordset
Dim stSql As String
Dim strGreeting As String

    Set rs = Application.CurrentDb.OpenRecordset("tblUsers", dbOpenDynaset)
    strUsername = UNameWindows ' the value of this is aaroni which does not exist in the DB
    rs.FindFirst "fldUname=" & """ & strUsername & """ 
    If Not rs.EOF Then
        strPname = rs("fldPname") 'filled with the first row in the DB
        intUserID = rs("fldUserID")'filled with the first row in the DB
    End If

    ' Close the recordset and the database.
    rs.Close
    Set rs = Nothing

End Sub
 
the line
rs.FindFirst "fldUname=" & """ & strUsername & """
should be
rs.FindFirst "fldUname=""" & strUsername & """"

but why not:

Code:
Sub GetUserdetails()
Dim rs As DAO.Recordset
Dim stSql As String, strGreeting As String, strUsername As String
    strUsername = UNameWindows ' the value of this is aaroni which does not exist in the DB
    Set rs = CurrentDb.OpenRecordset("SELECT * FROM tblUsers WHERE fldUname=""" & strUsername & """", dbOpenDynaset)
    If rs.RecordCount > 0 Then
        rs.MoveFirst
        strPname = rs!fldPname 'filled with the first row in the DB
        intUserID = rs!fldUserID 'filled with the first row in the DB
    End If
    rs.Close
    Set rs = Nothing
End Sub
 
Thank you very much :)
 

Users who are viewing this thread

Back
Top Bottom