syntax error in string in expression run-time error '3077':

awa786

Registered User.
Local time
Today, 08:14
Joined
Jul 7, 2015
Messages
23
Dear all,
I have a logout button on main menu form that logout the current user close the main form and open the login form and edit the logout time in table login history table, but when i click on the button, this message appeared
" syntax error in string in expression run-time error '3077': "

button contain following code and the User_name field in tbl_Login_History is text field.
table screenshot attached


Code:
intResponse = MsgBox("Warning: You are about to Logout" & Chr(13) & _
    "from database, Are you sure?", vbYesNo + vbExclamation, "Confirm")
    Set db = CurrentDb()
    Set rst = db.OpenRecordset("tbl_Login_History", dbOpenDynaset)
    Select Case intResponse
        Case vbYes
            [COLOR="Red"]rst.FindLast "Login_History_ID =  " & txtUser & "'"
[/COLOR]            rst.Edit
                rst!Time_Out = Now()
                
            rst.Update
            DoCmd.OpenForm "frmLogin"
            DoCmd.Close acForm, "frmDB6"
    End Select


thanks in advance
 

Attachments

  • TABLE LOGIN HISTORY.png
    TABLE LOGIN HISTORY.png
    6.3 KB · Views: 188
The ID is numeric do you don't want the single quote at the end (and in any case they're unbalanced, one after and none before). I'd open the recordset on an SQL statement that only pulled that record.
 
The ID is numeric do you don't want the single quote at the end (and in any case they're unbalanced, one after and none before).

can you explain please i am not advanced user of ms access.kindly suggest how to fix it.


thanks
 
if Login_History_ID is text then use

Code:
 rst.FindLast "Login_History_ID =  '" & txtUser & "'"

if a number use:


Code:
rst.FindLast "Login_History_ID =  " & txtUser
 
Login_History_ID is auto number ,but the txtUser is string value i.e "username" like "admin" on the form and in tbl_Login_History ref as "User_Name",
if user name is numeric value like "123","786" then
Code:
rst.FindLast "Login_History_ID =  " & txtUser
[/QUOTE]
this code works fine but in my case where txtUser has string value
i am getting following error:

Run-time error '3070':
The Microsoft office access database engine does not recognize 'admin' as a valid field name or expression.


please help...
 
sneuberg already jumped in with the answer. You'd have to use the user name field rather than the autonumber field.
 
Code:
rst.FindLast "User_Name =  '" & txtUser & "'"

maybe
 
Code:
rst.FindLast "User_Name =  '" & txtUser & "'"
I was making wrong reference in my code to the field, Login_History_ID instead of User_Name.
now its working.

i am very thankfull to Both pbaldy & sneuberg for helping me.

regards.

solved
 

Users who are viewing this thread

Back
Top Bottom