Results 1 to 3 of 3
  1. #1
    jimmyac23 is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Sep 2014
    Posts
    5

    Error message after setfocus method

    I have a combobox named 'ContactPosition' that I am requiring contain a value by having a warning message appear before the form updates if 'ContactPosition' is Null or is a zero string. I use the SetFocus method and it works successfully, but after my MsgBox appears, the error 2105 appears stating "you can't go to the specified record." After a lot of searching I do not know why this error is still occuring and do not know how to intercept a specific error. Thank you for your help and have a great weekend!



    Code:
    Option Compare Database
    
    Private Sub ContactType_AfterUpdate()
        ContactPosition.Requery
        ContactPosition.Value = ""
        Me.ContactType.SetFocus
    End Sub
    
    
    Private Sub Region_AfterUpdate()
        Borough.Requery
        Borough.Value = ""
        Neighborhood.Value = ""
    End Sub
    
    
    Private Sub Borough_AfterUpdate()
        Neighborhood.Requery
        Neighborhood.Value = ""
    End Sub
    
    
    Private Sub Form_BeforeUpdate(Cancel As Integer)
    
    
        'Contact Position
        If IsNull(Me.ContactPosition.Value) Or Me.ContactPosition.Value = "" Then
            MsgBox ("Please select a contact position.")
            Me.ContactPosition.SetFocus
        End If
    End Sub

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Need to cancel the update.

    If Me.ContactPosition & "" = "" Then
    MsgBox ...
    Cancel = True
    ...
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    The line June7 gave you

    Cancel = True

    in the Form_BeforeUpdate event, is the important thing, here! You can't interrupt the saving of the Form, which is what the Form_BeforeUpdate event does, in essence, to move Focus to the ContactPosition control. So first you have to cancel the saving/update

    Cancel = True

    as June7 said, then set Focus on ContactPosition.

    Linq ;0)>

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

Similar Threads

  1. Replies: 15
    Last Post: 11-01-2013, 03:24 PM
  2. Method or Data member not found error
    By junwatts in forum Access
    Replies: 1
    Last Post: 09-27-2013, 08:49 AM
  3. Outlook error message using SendObject method
    By Juan23 in forum Programming
    Replies: 3
    Last Post: 07-10-2013, 12:03 PM
  4. Replies: 7
    Last Post: 06-08-2012, 09:55 PM
  5. Error checking field, SetFocus does not work
    By SemiAuto40 in forum Access
    Replies: 9
    Last Post: 07-26-2011, 10:08 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