Results 1 to 3 of 3

Sending control to specific control

  1. #1
    wasim_sono is offline Advanced Beginner
    Windows XP Access 2013 64bit
    Join Date
    May 2005
    Location
    Pakistan
    Posts
    73

    Sending control to specific control

    Dear All



    I'm using the following code(which is a part of full code) but this is not working.
    Code:
                 If CD <> Right(con, 1) Then
                                            MsgBox " the check digit is " & CD
                                            MsgBox "Please Enter Correct Customer No"
                                            CONB.Undo
                                            Cancel = True
                          End if
    Here the variable con is equalize with form field "Conb". I'm using this code on after update event of control "CONB". after this code execution the control jumps to next field but I want that if check is wrong then control should stay at CONB field.

    Thanks.

    Wasim

  2. #2
    Join Date
    Nov 2006
    Location
    Arlington Heights, IL
    Posts
    7
    Are you familiar with the SetFocus property? If the check is wrong then set the focus at ConB.

    I believe the code is as simple as:

    "ConB.SetFocus"

    Thanks,
    ScottG

  3. #3
    Join Date
    Apr 2007
    Location
    Portsmouth, VA
    Posts
    5
    SetFocus will work, but it's not going to consistently work the way you want it to. If the user pressed Tab or Enter to finish the CONB entry, the setfocus will move the cursor back to CONB, but then the tab/enter will be executed, effectively putting your cursor in the next field. The behavior is different, depending on how the user attempted to exit the CONB field.

    The consistent way to handle what you're talking about is to move your code from the After_Update event to the Before_Update event. This will prevent the CONB field from losing scope until the problem is resolved.

    Take out the UNDO command, as it won't be needed for the Before_Update. The update hasn't happened yet, so there's nothing to undo.

    Also note that your command Cancel = True is correct for the Before_Update event (where you're moving your code to). However, it has no effect in the After_Update event where you currently have it, because there's no Cancel parameter in that event.

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

Similar Threads

  1. Access - Calendar Control
    By James890 in forum Forms
    Replies: 3
    Last Post: 04-01-2009, 04:52 PM
  2. Linked control in form
    By Zipster1967 in forum Forms
    Replies: 0
    Last Post: 04-14-2007, 01:40 PM
  3. No object in this control
    By mtrcar1 in forum Access
    Replies: 0
    Last Post: 10-12-2006, 05:31 PM
  4. Grid Control - or something like that.
    By rhunt in forum Programming
    Replies: 1
    Last Post: 12-15-2005, 04:46 PM
  5. Control addressing on subforms
    By JB in forum Access
    Replies: 1
    Last Post: 12-09-2005, 09:14 PM

Posting Permissions

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