Results 1 to 3 of 3
  1. #1
    ColPat is offline Novice
    Windows XP Access 2003
    Join Date
    May 2010
    Posts
    25

    SetFocus Problem

    Hi, hoping someone can help me with the following piece of Access code.

    The coAddNew command button unlocks the field AssetID and moves focus to the AssetID field. On update of the AssetID field code checks for existing record. If found focus should be set back to the AssetID field for re-entry.
    Problem is focus always goes to the field after the AssetID on.
    Can anyone explain what I am doing wrong, I thought Me.AssetID.SetFocus should force the cursor to go to that field, as it does in the AddNew bit of code, NOT the field after it.

    Many thanks



    Colin


    Private Sub AssetID_AfterUpdate()

    If Not IsNull(AssetID) Then
    If DCount("AssetID", "tbEqld", "[AssetID] = '" & AssetID & "'") > 0 Then
    MyMsg = MsgBox("Equipment ID Exists, Please Enter New ID or Click Cancel to Exit!", vbOKCancel, "Add New Equipment")
    If MyMsg = 1 Then
    Me.AssetID.SetFocus 'This SetFocus moves the cusor to the field after Me.AssetID
    Else
    Me.Undo
    DoCmd.GoToRecord , , acFirst
    Exit Sub

    End If
    End If
    End If
    'Me.AssetID.Locked = True

    End Sub
    __________________________________________________ ___________
    Private Sub coAddNew_Click()
    On Error GoTo Err_coAddNew_Click
    Me.AssetID.Locked = False
    'strSaveOption = "N"

    MyMsg = MsgBox("Enter New Equipment ID and Data or Cancel to Exit!", vbOKCancel, "Add New Equipment")
    If MyMsg = 1 Then
    DoCmd.GoToRecord , , acNewRec
    Me.AssetID.SetFocus ' This SetFocus works as it should and moves cursor to Me.AssetID
    Else
    Exit Sub
    End If
    Exit_coAddNew_Click:
    Exit Sub

    Err_coAddNew_Click:
    MsgBox Err.Description
    Resume Exit_coAddNew_Click

    End Sub
    Last edited by ColPat; 06-21-2010 at 04:48 AM.

  2. #2
    evander is offline Competent Performer
    Windows 7 Access 2003
    Join Date
    Apr 2010
    Location
    Philippines
    Posts
    206
    Private Sub AssetID_AfterUpdate()

    If Not IsNull(AssetID) Then
    If DCount("AssetID", "tbEqld", "[AssetID] = '" & AssetID & "'") > 0 Then
    MyMsg = MsgBox("Equipment ID Exists, Please Enter New ID or Click Cancel to Exit!", vbOKCancel, "Add New Equipment")
    If MyMsg = 1 Then
    Me.AssetID.SetFocus
    Else
    Me.Undo
    DoCmd.GoToRecord , , acFirst
    Exit Sub

    End If
    End If
    End If
    Me.AssetID.Locked = True
    If you set focus on the control, then lock it anyway, the focus shifts away, into the next control that is not locked.

  3. #3
    ColPat is offline Novice
    Windows XP Access 2003
    Join Date
    May 2010
    Posts
    25
    Thanks for that. However I have commented out the lock function and still the cursor moves to the next field.
    Only way I can get it to work is to set focus to the field the cursor moves to and then set focus back to the field I want the cursor in.
    Just seems a messy way of achieving the result I want

    Any other ideas most welcome.
    Last edited by ColPat; 06-26-2010 at 04:54 PM.

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

Similar Threads

  1. Replies: 2
    Last Post: 06-14-2010, 03:25 PM
  2. query problem i have a problem wi
    By maxx3 in forum Queries
    Replies: 0
    Last Post: 06-29-2009, 02:29 AM
  3. SetFocus Issue
    By Sinjin in forum Access
    Replies: 0
    Last Post: 02-14-2008, 07:31 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