Results 1 to 7 of 7
  1. #1
    Join Date
    May 2012
    Posts
    137

    Unanswered: dependent button

    There is a form with some fields and it has a button which goes to the next records. how can we make the button inactive otherwise all or some of the filed are filed?
    Thank you
    ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
    I asked god to please give me everything to enjoy the life, God said: i gave you the life to enjoy everything.

  2. #2
    Join Date
    Feb 2004
    Location
    New Zealand
    Posts
    1,476
    Provided Answers: 11
    Have you look into the Form_Current() event
    hope this help

    StePhan McKillen
    the aim is store once, not store multiple times
    Remember... Optimize 'til you die!
    Progaming environment:
    Access based on my own environment: DAO3.6/A97/A2000/A2003/A2007/A2010
    VB-NET based on my own environment started 2007
    SQL-2005 based on my own environment started 2008
    YOUR PASSWORD IS JUST LIKE YOUR TOOTHBRUSH DON'T SHARE IT.
    DONT WORRY ABOUT THOSE WHO TALK BEHIND YOUR BACK
    THEY'RE BEHIND YOU FOR A REASON

  3. #3
    Join Date
    May 2012
    Posts
    137
    please give me more help man,
    what should i do in the Form_current() event. The button has a function such as taking to the next record or opening a report else,. i want it to be inactive untill all the blanks in the forma are properly filled. do i need to write a VBA or somthing? where should i put that?
    thank you
    ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
    I asked god to please give me everything to enjoy the life, God said: i gave you the life to enjoy everything.

  4. #4
    weejas is offline Grumpy old man (training)
    Join Date
    Sep 2006
    Location
    Surrey, UK
    Posts
    1,095
    Provided Answers: 17
    Yes, you will need to write some VBA. In the properties box for the form, select the "Events" tab. In the combo box for "On Current", select "[Event Procedure]" and click the ellipsis button ("..."). This will open the VBA code editor and create the bare bones of the Form_Current() subroutine.

    In order to write the code:
    • Work out which controls must have values in them for the command button to be available
    • Work out how to keep track of which are valid and which are not
    • Write a conditional statement that enables or disables the command button according to the validity of the other controls


    You'll probably find more help forthcoming if you have a go and post your attempts, along with any unexpected behaviour or results.
    10% of magic is knowing something that no-one else does. The rest is misdirection.
    Beers earned: 2

  5. #5
    Join Date
    May 2012
    Posts
    137
    i tried this code in the VBA code part:
    Code:
    Private Sub Form_Current()
    If 10 > 0 Then
      Me.moresale.Enabled = True
    Else
      Me.moresale.Enabled = False
    End If
    End Sub
    it is obiouse that 10 is greater then zero. So the button was enabled. Then i inserted 10 <0 , and the button was disabled since 10 is obviously more than 0.

    But when it did not work when i made the actual condition as the following:

    Code:
    Private Sub Form_Current()
    If Len(Me.phone) > 0 Then
      Me.moresale.Enabled = True
    Else
      Me.moresale.Enabled = False
    End If
    End Sub
    Now the button was always disabled, either the control name (phone) is blank or is filed correctly.
    i dont know what goes wrong when put a condition instead of an obviouse statement.

    i have attached the DB here.
    thank you
    Attached Files Attached Files
    ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
    I asked god to please give me everything to enjoy the life, God said: i gave you the life to enjoy everything.

  6. #6
    weejas is offline Grumpy old man (training)
    Join Date
    Sep 2006
    Location
    Surrey, UK
    Posts
    1,095
    Provided Answers: 17
    I think that you need to have the form bound to a table in order for the Current event to work.
    10% of magic is knowing something that no-one else does. The rest is misdirection.
    Beers earned: 2

  7. #7
    Join Date
    Dec 2016
    Posts
    22
    Ariansman,
    here is the code that I wrote to stop the button from working if 3 different fields were not filled out.
    Hope it helps.

    Code
    Code:
    Private Sub SubmitForm_Click()
    On Error GoTo SubmitForm_Click_Err
    
    ' Check for a blank teamnumber, teachnumber, and date
    If IsNull(teamnum.Value) Or IsNull(checkedout.Value) Then
    MsgBox ("The Team Number & Date must be entered.")
    GoTo ErrorExit
    End If
    
    If IsNull(teachnum.Value) Then
    MsgBox ("Must have a Teach Number too!")
    GoTo ErrorExit
    End If
    
    If IsNull(TeachDay.Value) Or IsNull(TeachDate.Value) Or IsNull(TeachTime.Value) Or IsNull(kit.Value) Or IsNull(copies.Value) Then
    MsgBox ("Yea, those other grey boxes need to be filled out too.")
    GoTo ErrorExit
    End If
    
    DoCmd.SetWarnings False
    DoCmd.OpenQuery "UpdateQuantity"
    
    SubmitForm_Click_Exit:
        Exit Sub
    
    
    SubmitForm_Click_Err:
        MsgBox Error$
        Resume SubmitForm_Click_Exit
    
    'this errorexit is from the goto above if the team number is blank
    ErrorExit:
    
    End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •