+ Reply to Thread
Results 1 to 9 of 9

Stop Button Working Before Form is Complete

Hybrid View

  1. #1
    Registered User
    Join Date
    06-10-2011
    Location
    England
    MS-Off Ver
    Excel 2003
    Posts
    5

    Stop Button Working Before Form is Complete

    Hey

    Hopefully someone can help me with this. I'm very new at VBA and am kind of muddling my way through

    I have some code to make the SUBMIT button selectable only after one of the Option boxes (client/agent) is filled, but I also have a username drop down box (user) and two other drop down boxes (calltype and details). How can I make it that the SUBMIT button doesn't work until ALL fields are filled? The code is below for what I already have and attached is a look at the form.

    Clipboard01.jpg

    Any help with these would be greatly appreciated...I'm pretty stuck. If you need any further clarification, please let me know.

    Apologies if the code is ugly...I'm new to all this!

    SUBMIT button code:
    Private Sub Client_Change()
    
    SUBMIT.Enabled = Client
    
    End Sub
    
    Private Sub agent_Change()
    
    SUBMIT.Enabled = Agent
    
    End Sub
    
    Private Sub UserForm_Initialize()
    
    SUBMIT.Enabled = False
    
    End Sub
    Last edited by y2drew; 06-12-2011 at 04:36 AM.

  2. #2
    Registered User
    Join Date
    06-10-2011
    Location
    England
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: VBA code issues

    Thanks tigeravatar! Apologies, missed that bit

  3. #3
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Stop Button Working Before Form is Complete

    Is Client declared as a Boolean Variable or is the name of an Option Box or CheckBox?

    The enabled will only be true if Client is True
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  4. #4
    Registered User
    Join Date
    06-10-2011
    Location
    England
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Stop Button Working Before Form is Complete

    Client is the name of the Option Box.

    So I'd need it to be a Bootlean Variable to give what I want. Any advice on how to go about this?


  5. #5
    Registered User
    Join Date
    05-11-2011
    Location
    College Station, Texas
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    42

    Re: Stop Button Working Before Form is Complete

    Hi,

    If you can attach a sample workbook, I can do that for you

    Thanks and Best Regards,
    Abi
    Abi

  6. #6
    Registered User
    Join Date
    06-10-2011
    Location
    England
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Stop Button Working Before Form is Complete

    That would be great, thanks Abi!
    Attached Files Attached Files

  7. #7
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Stop Button Working Before Form is Complete

    Try this
    Private Sub Client_Change()
        If bCombos Then Me.SUBMIT.Enabled = bCombos
    End Sub
    
    Private Sub agent_Change()
        If bCombos Then Me.SUBMIT.Enabled = bCombos
    End Sub
    Private Sub UserForm_Initialize()
        SUBMIT.Enabled = False
    End Sub
    Function bCombos() As Boolean
        Dim oCtrl As MSForms.Control
        Dim iX As Integer
       iX = 0
        For Each oCtrl In Me.Controls
            If TypeName(oCtrl) = "ComboBox" Then
                If oCtrl.Value <> Empty Then iX = iX + 1
            End If
        Next oCtrl
        If iX = 3 Then bCombos = True
    End Function
    Last edited by royUK; 06-13-2011 at 01:39 PM.

  8. #8
    Registered User
    Join Date
    06-10-2011
    Location
    England
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Stop Button Working Before Form is Complete

    Hey!

    This seems to almost work, the only thing is that if you select one of the option boxes and then fill in the rest, you have to change the option box again for the "SUBMIT" button to work.

    I've attached a copy for testing.

    Thanks for the help!

    Attached Files Attached Files

  9. #9
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Stop Button Working Before Form is Complete

    The way you have the form set up you will need to click the option again. I can't really see why you have two option boxes.

    Private Sub Client_Click()
        If bCombos Then
            Me.SUBMIT.Enabled = bCombos
        Else: Me.Client = False
            MsgBox "Complete all entries"
        End If
    End Sub
    
    Private Sub agent_Click()
        If bCombos Then
            Me.SUBMIT.Enabled = bCombos
        Else: Me.Agent = False
            MsgBox "Complete all entries"
        End If
    End Sub
    Private Sub UserForm_Initialize()
        SUBMIT.Enabled = False
    End Sub
    Function bCombos() As Boolean
        Dim oCtrl As MSForms.Control
        Dim iX As Integer
        iX = 0
        For Each oCtrl In Me.Controls
            If TypeName(oCtrl) = "ComboBox" Then
                If oCtrl.Value <> Empty Then iX = iX + 1
            End If
        Next oCtrl
        If iX = 3 Then bCombos = True
    End Function

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1