Results 1 to 3 of 3
  1. #1
    OwlMan is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2011
    Posts
    2

    Question Set Focus not working as it did in Access 2003

    Hi All

    I am a teacher who has to teach my class a small amount of VB programming, however programming is not my strong point, hence my need for help. In previous years I have taught them a password routine for Access. It is a very simple routine: a password is entered in to a form and if it is correct then the switchboard opens. The code has always worked in Access 2003 but our establishment has now switched to 2010 and the code no longer works. The problem seems to be with the SetFocus section of code. The code I am using is as follows:

    Dim db As DAO.Database


    Dim rs As DAO.Recordset
    Set db = CurrentDb

    Set rs = db.OpenRecordset("select * from tblPassword where password = '" & Text0.Value & "'")

    If rs.EOF Then
    MsgBox ("Incorrect Password. Please Try Again")

    Else

    Form_Switchboard.SetFocus

    DoCmd.Close asForm, "frmPassword"

    End If


    I would be very grateful if someone could advise me what the problem is with the highlighted line of code. As I said, this always worked fine in 2003.

    Many thanks

  2. #2
    Toyman is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Posts
    233
    Quote Originally Posted by OwlMan View Post
    Hi All

    I am a teacher who has to teach my class a small amount of VB programming, however programming is not my strong point, hence my need for help. In previous years I have taught them a password routine for Access. It is a very simple routine: a password is entered in to a form and if it is correct then the switchboard opens. The code has always worked in Access 2003 but our establishment has now switched to 2010 and the code no longer works. The problem seems to be with the SetFocus section of code. The code I am using is as follows:

    Dim db As DAO.Database
    Dim rs As DAO.Recordset
    Set db = CurrentDb

    Set rs = db.OpenRecordset("select * from tblPassword where password = '" & Text0.Value & "'")

    If rs.EOF Then
    MsgBox ("Incorrect Password. Please Try Again")

    Else

    Form_Switchboard.SetFocus

    DoCmd.Close asForm, "frmPassword"

    End If


    I would be very grateful if someone could advise me what the problem is with the highlighted line of code. As I said, this always worked fine in 2003.

    Many thanks
    You are missing the opening code for the "switchboard". Should look something like this:

    Dim db As DAO.Database
    Dim rs As DAO.Recordset
    Set db = CurrentDb

    Set rs = db.OpenRecordset("select * from tblPassword where password = '" & Text0.Value & "'")

    If rs.EOF Then
    MsgBox ("Incorrect Password. Please Try Again")

    Else

    docmd.OpenForm "Form_Switchboard",acNormal
    Form_Switchboard.SetFocus

  3. #3
    OwlMan is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2011
    Posts
    2
    Many thanks. I will give this a go

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

Similar Threads

  1. ListBox RowSource Update Not working in 2003
    By Access0307 in forum Programming
    Replies: 1
    Last Post: 05-05-2011, 07:41 PM
  2. Replies: 1
    Last Post: 08-17-2010, 11:24 PM
  3. Replies: 1
    Last Post: 04-03-2010, 09:35 PM
  4. Macros not working in 2003
    By SnowCker in forum Access
    Replies: 1
    Last Post: 01-21-2010, 03:20 PM
  5. Replies: 1
    Last Post: 09-06-2006, 11:48 AM

Tags for this Thread

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