Results 1 to 4 of 4
  1. #1
    Join Date
    Dec 2005

    Unanswered: Using SetFocus on Form not working

    I am working on a new form and to help validate duplicate entries, on the AfterUpdate event, I am running a quick check for a duplicate scan. It works fine, except when it gets to the point where it nulls the [2Tote] field, it moves on to the next field. I added a SetFocus command line to move it back to the [2Tote] field, however it is ignoring this line and remaining in the next field on the form. Any suggestions?

    Private Sub Ctl2Tote_AfterUpdate()

    If DCount("[ToteNumber]", "RTV", "[ToteNumber]= Forms![RTV Pallet Build]![2Tote]") > 0 Then
    Forms![RTV Pallet Build].Visible = False
    [2Tote].Value = Null
    DoCmd.OpenForm "RTV Tote Scanned Twice Error"
    End If

    End Sub

  2. #2
    Join Date
    Apr 2005
    Zagreb - Croatia
    As I can see, you can't to SetFocus on 2Tote field becasuse the form is unvisible.

  3. #3
    Join Date
    Nov 2009

    Instead of using Null could you just use

    [2Tote].value = ""

    Or does it have to be Null?

    You could also move that bit of coding up to before making the subform invisible, just like MStef pointed out you can't set a focus to something that isn't there (2TOTe is on a subform you have just made invisible).


  4. #4
    Join Date
    Jun 2005
    Richmond, Virginia USA
    Provided Answers: 19
    There's two problems here.

    First, you've named your control 2Tote. Access doesn't like object names that begin with digits! In the VBA Editor it prefixes them with Ctl, giving you Ctl2Tote.

    Secondly, you cannot set focus to a control from an event of that control. If you have to do it like this, you need to set focus to another control then set focus back to the control in question.

    But what you should really be doing here is to place your code in the

    Ctl2Tote_BeforUpdate(Cancel as Integer)

    event. Then, instead of setting the focus back to 2Tote, you simply use the line

    Cancel = True

    which cancels the update and leaves the focus in the Ctl2Tote control.
    Hope this helps!

    The problem with making anything that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts