Page 1 of 2 12 LastLast
Results 1 to 15 of 20
  1. #1
    ariansman is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2013
    Posts
    57

    dependent button

    There is a form with some fields and 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

  2. #2
    andy49's Avatar
    andy49 is offline VIP
    Windows 10 Access 2007
    Join Date
    Nov 2016
    Location
    London
    Posts
    1,051
    Quote Originally Posted by ariansman View Post
    There is a form with some fields and a button which goes to the next records.
    Can you show us what you mean? maybe take a photo of the screen and add it here?

  3. #3
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    I'd create a form level function and call if from the after update event of the relevant controls. That function would test them all, and enable/disable the button as appropriate.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  4. #4
    ariansman is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2013
    Posts
    57
    thank you, but how can i make that? i mean imagine there are three blank spaces tobe filed, named: blank1, blank2, blank3. and the button is supposed to go to thext record. but i want it to be active only if all the blanks are filed with appropriate data.
    how should i write the function? is that a VB? where should i put the code?
    thank you

  5. #5
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    You could add code in the button OnClick event which checks all the fields and does not go to the next record unless all the fields have values.

  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,521
    Quote Originally Posted by ariansman View Post
    thank you, but how can i make that? i mean imagine there are three blank spaces tobe filed, named: blank1, blank2, blank3. and the button is supposed to go to thext record. but i want it to be active only if all the blanks are filed with appropriate data.
    how should i write the function? is that a VB? where should i put the code?
    thank you
    Yes, VBA code. Code for a particular event goes here:

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

    A form level function would go at the top of the form's code:

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

    The code itself might look like:

    Code:
    If Len(Me.FirstControl & vbNullString) > 0 AND Len(Me.SecondControl & vbNullString) > 0 Then
      Me.ButtonName.Enabled = True
    Else
      Me.ButtonName.Enabled = False
    End If
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    ariansman is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2013
    Posts
    57
    Thank you,
    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.
    thank you

  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,521
    Can you attach the db here?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  9. #9
    ariansman is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2013
    Posts
    57
    thank you for helping me out. here is the DB. i upladed to my site hosting.
    Last edited by ariansman; 01-26-2017 at 12:17 PM.

  10. #10
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    I don't download from unknown sites, but perhaps somebody else can.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  11. #11
    ariansman is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2013
    Posts
    57
    it is understandable, but i couldnt find a way to attach it here. thank you BTW

  12. #12
    ariansman is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2013
    Posts
    57
    there is no need to download my DB sicne it is very easy to make it. i made a new DB, with two forms. form1 and form2. form1 has a blank named "phone" and a buttom named "moresale". the button is supposed to open form2 if activated. then i put the above VBA in the code of form one. you will see that it is not working. any help is appreciated.

  13. #13
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    You can attach a db in the "Go Advanced" area. If it's larger, zip first.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  14. #14
    ariansman is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2013
    Posts
    57
    good, thank you , i attached it here. in the zip form
    test2017.zip

  15. #15
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    As I said originally, the code needs to run from the after update event of the number textbox. The current event only fires when changing records or on load, which is irrelevant with an unbound form. More here:

    http://www.baldyweb.com/ConditionalVisibility.htm
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Dependent Value
    By Ramtrap in forum Access
    Replies: 1
    Last Post: 12-19-2016, 11:56 AM
  2. Dependent ComboBoxes
    By HansJ in forum Forms
    Replies: 3
    Last Post: 06-09-2016, 05:12 PM
  3. (Again) dependent fields,
    By jamal numan in forum Access
    Replies: 12
    Last Post: 10-25-2012, 07:17 AM
  4. Help with dependent values
    By ceejsing in forum Access
    Replies: 6
    Last Post: 08-05-2011, 06:36 AM
  5. Dependent Combo Box
    By tigers in forum Forms
    Replies: 1
    Last Post: 06-16-2009, 12:46 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