Results 1 to 7 of 7
  1. #1
    gradygoose is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Posts
    4

    Access 2010 Require field entry if certain combobox value selected


    I have a combobox that has just two choices "open" or "closed", if closed is chosen I want to require a different field, a text box (date), to be
    entered.

    The code I used is:

    Private Sub opcl_BeforeUpdate(Cancel As Integer)
    If opcl = "closed" Then
    MsgBox "Please enter date closed", vbOKOnly
    compdate.SetFocus
    Cancel = True
    End If
    End Sub

    However, this produces the following error message:
    Run-Time error 2108
    You must save the field before you execute the GoToControl action,
    the GoTo mtehod, or the SetFocus method.

    PS I am a newbie to access programming.
    Thank you in advance for any help.

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    The Cancel = True will hold the focus in the current control.

  3. #3
    gradygoose is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Posts
    4

    Removed Cancel=true, still receive same error msg

    Thanks RuralGuy but after removing the line of code Cancel=True
    I still receive the exact same error message

    Run-Time error 2108
    You must save the field before you execute the GoToControl action,
    the GoTo mtehod, or the SetFocus method.

  4. #4
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    You can't change the focus in the BeforeUpdate event of a control. You could do this in the AfterUpdate event if that is how you want to proceed. I would probably tell the user to enter a date first and issue a Me.opcl.UnDo in the BeforeUpdate event and leave the Cancel = True in the code but remove the SetFocus. Just my $0.02

  5. #5
    gradygoose is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Posts
    4

    Date field

    RuralGuy

    The whole point is they are marking the "open closed" field closed, and not remembering to put a date in the date field. I wish it was as simple as telling them to enter the date but that is not working which is why I am trying to require the date field based on "closed" being chosen.

    Thanks,

  6. #6
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    I understood that. I was suggesting a message box letting the user know why the system will not let them mark it as closed yet. The only thing I was leaving out was setting the focus to the date control.

  7. #7
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Since the *only* reason to be in this ComboBox is to mark it "Closed", you might try using the OnEnter or GotFocus events to move the focus back to the Date control. That may not work as you want it to work and has some undesirable side effects so try playing with the OnChange event of the cbo.

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

Similar Threads

  1. Replies: 2
    Last Post: 05-11-2011, 09:06 AM
  2. Replies: 9
    Last Post: 12-18-2010, 12:51 PM
  3. Problems with data entry form Access 2010
    By OfficeQuestions in forum Access
    Replies: 4
    Last Post: 09-23-2010, 01:42 PM
  4. SetFocus/Require Entry
    By mbake085 in forum Programming
    Replies: 5
    Last Post: 08-19-2010, 07:32 AM
  5. Replies: 1
    Last Post: 07-14-2010, 01:34 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
  •  
Other Forums: Microsoft Office Forums