Results 1 to 5 of 5
  1. #1
    anwaar is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Aug 2011
    Posts
    18

    Call Last record in Table using Access VBA

    Guys,

    Can anyone help me out, I have a login form programmed in Access VBA which take username and password, match it with original values (username, password) and store both of them along with login date/time in a seprate table named as "LoginAttempts". Now the problem is, I want to call the last record of "LoginAttempts" table (username of last user who log in) in another form.

    Please help me out to make it possible??

  2. #2
    eww is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Aug 2010
    Posts
    125
    I think there are a few different ways you could go about doing this, my choice would be to create a small query for the form you want, pulling the username and max date/time out of the table:

    Code:
    SELECT username, Max(datetime) FROM table GROUP BY username;

  3. #3
    anwaar is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Aug 2011
    Posts
    18
    Thanks Eric,

    I have try to call Maximum LoginDate but when I run the query it ask me for LoginDate Perameter. I mean It should autometically pick Maximum LoginDate from table??

  4. #4
    eww is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Aug 2010
    Posts
    125
    Sorry, this one was a little trickier than I originally thought. Not sure what was the parameter issue you were having, but this might fix it anyway. The correct query you want to use would be:

    Code:
    SELECT LoginDate, Username FROM yourtable WHERE LoginDate IN (SELECT Max(LoginDate) FROM yourtable);
    With the first one you would have got the latest LoginDate for each user, and I'm assuming you want the latest user's login.

  5. #5
    anwaar is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Aug 2011
    Posts
    18
    Thanks Eric,

    Both of your examples really help me to get my required results

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Record count in Access table using VBA
    By shubhamgandhi in forum Programming
    Replies: 2
    Last Post: 07-20-2011, 11:59 AM
  2. Use VBA to call stored SQL from table
    By hcruz in forum Programming
    Replies: 2
    Last Post: 05-02-2011, 08:26 AM
  3. Assign and call variable from table
    By smikkelsen in forum Access
    Replies: 7
    Last Post: 04-01-2010, 09:38 AM
  4. Replies: 0
    Last Post: 05-07-2009, 02:32 PM
  5. Call Excel Data into Access table
    By jiguvaidya in forum Import/Export Data
    Replies: 0
    Last Post: 09-15-2008, 04:58 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums