Results 1 to 8 of 8
  1. #1
    tcheck is offline Competent Performer
    Windows 7 Access 2007
    Join Date
    Nov 2010
    Posts
    131

    Before Update

    I have a form that has a combo box where I check to see if a field in the header is filled in, if it is not I want an error message to come up and tell the user to enter a period. This works fine if I put the code in the On Got Focus Event. The problem is that when I open the form I get the message that they need to enter the period. I tried the Before Update Event and then it will not take the user to the Period field after they click OK.

    Here is my code;

    Private Sub AccountNumberSelect_GotFocus()
    If IsNull([PeriodSelect]) Then
    Dim LResponse As Integer
    LResponse = MsgBox("Please Enter a Period from Above!", vbYes, "Enter Period")

    Not sure where it would work best, like I said on Got Focus works fine except the message comes up when they open the form.

    Thanks in advance.
    DoCmd.GoToControl "PeriodSelect"


    End If
    End Sub

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,642
    I personally would use the form's before update event:

    http://www.baldyweb.com/BeforeUpdate.htm

    I suppose you could use the focus event, but you wouldn't want that control to get focus before the other, which it sounds like it does.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    tcheck is offline Competent Performer
    Windows 7 Access 2007
    Join Date
    Nov 2010
    Posts
    131
    When I use the before update event I get the follwoing error message;

    Run-Time error '2108'

    You must save the field before you execute the GoToControl action, the GoToControl method , or the SetFocus method.

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,642
    What's the code now? You probably need the Cancel = True and perhaps an Undo on that control.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    tcheck is offline Competent Performer
    Windows 7 Access 2007
    Join Date
    Nov 2010
    Posts
    131
    Private Sub AccountNumberSelect_BeforeUpdate(Cancel As Integer)
    If Len(Me.PeriodSelect & vbNullString) = 0 Then
    MsgBox "Please Enter a Period from the dropdown above!"
    Cancel = True
    Me.PeriodSelect.SetFocus
    End If
    End Sub

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,642
    As I mentioned, I would use the form's before update event, not a control's. That said, a control's might work. Did you try

    Me.AccountNumberSelect.Undo

    after Cancel = True?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    tcheck is offline Competent Performer
    Windows 7 Access 2007
    Join Date
    Nov 2010
    Posts
    131
    That worked. Thanks again.

  8. #8
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,642
    Happy to help.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Update 2 tables with one Update Query
    By Douglasrac in forum Queries
    Replies: 4
    Last Post: 04-14-2011, 08:33 AM
  2. Replies: 1
    Last Post: 01-22-2011, 12:23 PM
  3. Update field in table after update on a subform
    By jpkeller55 in forum Queries
    Replies: 3
    Last Post: 09-30-2010, 08:02 PM
  4. Update Query- selective update?
    By stephenaa5 in forum Queries
    Replies: 1
    Last Post: 10-29-2009, 11:15 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