Results 1 to 6 of 6
  1. #1
    ETCallHome is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Mar 2011
    Location
    Limpopo, South Africa
    Posts
    48

    Wink Changing Action on a Command Button

    Hi Guys/Gals,

    I need your expertise here... I created a command button to open a form. I also built validation code to check that all required fields have been entered. If all the fields are entered, then the command button action to open the form is actioned. However, if all the required fields are not entered, I want the command button action not to execute. Here is my questions...

    1. How do I stop the command button from opening the form is all the required data is not entered?
    2. In which event procedure due I enter the code?

    Your assistance is highly appreciated.

    Thanks

  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
    Where have you put the validation code?

  3. #3
    ETCallHome is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Mar 2011
    Location
    Limpopo, South Africa
    Posts
    48
    Hi Allan,

    I actually resolved this issue by disabling the command buttons when the form is loaded... Me.FormName.Enable = False, and only when all the required fields have been entered do I enable the command buttons... Me.FormName.Enable = True. However, I have different problem now... as follows:

    1. On the Lost Focus event, I validate whether the field is null, if it is.. I setup a msgbox prompting the user to enter the required field and set the focus back to the field.
    2. The validation is working and the msgbox is displayed successfully, but it sets the focus to the next field according to the Tab Index... not sure why it doing this... see code below:

    Private Sub Field_LostFocus()
    If IsNull(Me.Field) Then
    MsgBox "Please enter field as it is required"
    Me.Field.SetFocus
    End If
    End Sub

  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 need to use the Exit event rather than the LostFocus event and then simply use Cancel = True to keep the focus in the current control. Don't forget to use the Thread Tools and mark this thread as Solved when appropriate.

  5. #5
    ETCallHome is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Mar 2011
    Location
    Limpopo, South Africa
    Posts
    48
    Thanks Allan... I put it on Exit Event and it work fine...

  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
    Glad we could help.

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

Similar Threads

  1. Changing Field Values with Command Button
    By avarusbrightfyre in forum Access
    Replies: 1
    Last Post: 08-22-2010, 12:48 PM
  2. Replies: 1
    Last Post: 07-27-2010, 02:27 PM
  3. command or action " isn't available
    By laqsb in forum Access
    Replies: 3
    Last Post: 07-23-2010, 10:29 AM
  4. The command or action Quit isn't available
    By Macallan60 in forum Access
    Replies: 0
    Last Post: 04-26-2010, 09:59 AM
  5. No action button
    By dlewicki in forum Forms
    Replies: 6
    Last Post: 12-02-2009, 12:58 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