+ Reply to Thread
Results 1 to 7 of 7

Userforms help

Hybrid View

  1. #1
    Registered User
    Join Date
    02-11-2017
    Location
    Manchester, england
    MS-Off Ver
    2010
    Posts
    6

    Cool Userforms help

    Hi Guys,

    I have the below code and I think it is correct but it doesn't seem to call any subs when I hit OK if the checkboxes are checked. The other issue is when I hit okay and nothing is typed in the analyst name textbox, this comes up with a warning msg, as it should do, however whenever I leave one of the others blank it displays error messages for all the textboxes being blank even if they are not!

    Just as an FYI, I have the checkboxes enter a value of true or false respectively into a spreadsheet next to the respective name, this is then copied next to it when you hit okay to remember the settings in case the user reopens the form changes the checkboxes and hits cancel. Cancel copies the saved options over the referenced ones for the subs to be called

    Any ideas would be really handy!


    
    Private Sub CheckBoxCUST_Click()
    If CheckBoxCUST.Value = True Then
    Sheets("VBA inputs").Range("B3").Value = "TRUE" 'Check
    Else
    Sheets("VBA inputs").Range("B3").Value = "FALSE" 'UnCheck
    End If
    End Sub
    
    Private Sub CheckBoxSUP_Click()
    If CheckBoxSUP.Value = True Then
    Sheets("VBA inputs").Range("B2").Value = "TRUE" 'Check
    Else
    Sheets("VBA inputs").Range("B2").Value = "FALSE" 'UnCheck
    End If
    End Sub
    
    Private Sub CheckBoxTRANS_Click()
    If CheckBoxTRANS.Value = True Then
    Sheets("VBA inputs").Range("B4").Value = "TRUE" 'Check
    Else
    Sheets("VBA inputs").Range("B4").Value = "FALSE" 'UnCheck
    End If
    End Sub
    
    Private Sub CANCEL_Click()
    
    Dim VBAinp As Worksheet
    Dim CUST As Range
    Dim SUP As Range
    Dim Trans As Range
    Set VBAinp = Sheets("VBA inputs")
    Set CUST = VBAinp.Range("B2")
    Set SUP = VBAinp.Range("B3")
    Set Trans = VBAinp.Range("B4")
    
    
    ToolSelec.Hide
    VBAinp.Range("C2:C4").Copy Destination:=Sheets("VBA inputs").Range("B2:B4")
    
    If CUST.Value = "True" Then
    CheckBoxCUST.Value = True 'Check
    ElseIf CUST.Value = "FALSE" Then
    CheckBoxCUST.Value = False 'UnCheck
    End If
    
    If SUP.Value = "True" Then
    CheckBoxSUP.Value = True 'Check
    ElseIf SUP.Value = "FALSE" Then
    CheckBoxSUP.Value = False 'UnCheck
    End If
    
    If Trans.Value = "True" Then
    CheckBoxTRANS.Value = True 'Check
    ElseIf Trans.Value = "FALSE" Then
    CheckBoxTRANS.Value = False 'UnCheck
    End If
    
    Sheets("Transaction").Activate
    
    End Sub
    
    Private Sub ButtonOK_Click()
    
    Dim VBAinp As Worksheet
    Dim CUST As Range
    Dim SUP As Range
    Dim Trans As Range
    Set VBAinp = Sheets("VBA inputs")
    Set CUST = VBAinp.Range("B3")
    Set SUP = VBAinp.Range("B2")
    Set Trans = VBAinp.Range("B4")
    
    ToolSelec.Hide
    VBAinp.Range("B2:B4").Copy Destination:=VBAinp.Range("C2:C4")
    
    If CUST.Value = "true" Then
        'Call Customers
    End If
    If SUP.Value = "TRUE" Then
        Call Suppliers
    End If
    If Trans.Value = "TRUE" Then
        Call Transaction_Freq
    End If
    
    End Sub

  2. #2
    Forum Expert gmr4evr1's Avatar
    Join Date
    11-24-2014
    Location
    Texas
    MS-Off Ver
    Office 2010 and 2007
    Posts
    3,448

    Re: Userforms help

    You may have to attach a workbook with the userform and code in it so we can get a better understanding of what is (or isn't) happening to help out with this.
    1N73LL1G3NC3 15 7H3 4B1L17Y 70 4D4P7 70 CH4NG3 - 573PH3N H4WK1NG
    You don't have to add Rep if I have helped you out (but it would be nice), but please mark the thread as SOLVED if your issue is resolved.

    Tom

  3. #3
    Registered User
    Join Date
    02-11-2017
    Location
    Manchester, england
    MS-Off Ver
    2010
    Posts
    6

    Re: Userforms help

    Thanks for the reply!

    That does make sense

    Here it is, I have taken out the main code, as the version I have at home isn't completed and would give endless errors.

    The forms with the issues are toolselec and analyst input. the checkboxes in toolselec refer to subs in "MainCode"
    Attached Files Attached Files

  4. #4
    Valued Forum Contributor
    Join Date
    06-21-2013
    Location
    Bangladesh
    MS-Off Ver
    Excel 2000, Excel XP, Excel 2002, Excel 2007, Excel 2010, Excel 2013
    Posts
    975

    Re: Userforms help

    You have done a mistake here :
    If CUST.Value = "True" Then
        'Call Customers
    End If
    If SUP.Value = "True" Then
        Application.Run "Suppliers"
    End If
    If Trans.Value = "True" Then
        Call Transaction_Freq
    End If
    As True/False are Boolean they will not be bounded with double inverted comma. Correct them as below :
    If CUST.Value = True Then
        'Call Customers
    End If
    If SUP.Value = True Then
        Application.Run "Suppliers"
    End If
    If Trans.Value = True Then
        Call Transaction_Freq
    End If

  5. #5
    Registered User
    Join Date
    02-11-2017
    Location
    Manchester, england
    MS-Off Ver
    2010
    Posts
    6

    Re: Userforms help

    Thanks! that worked, anything for my other issue?

    On the analyst input form,when I hit okay and nothing is typed in the analyst name textbox, this comes up with a warning msg, as it should do, however whenever I leave one of the others blank it displays error messages for all the textboxes being blank even if they are not!

  6. #6
    Valued Forum Contributor
    Join Date
    06-21-2013
    Location
    Bangladesh
    MS-Off Ver
    Excel 2000, Excel XP, Excel 2002, Excel 2007, Excel 2010, Excel 2013
    Posts
    975

    Re: Userforms help

    Thanks for the rep. For the error message you have used below code :
    Private Sub OK_Click()
    
    If AnalystName.Value = "" Then
    GoTo Analysterr
    Exit Sub
    ElseIf Sortcode.Value = "" Then
    GoTo SCerr
    Exit Sub
    ElseIf AccNo.Value = "" Then
    GoTo ACCnoerr
    Exit Sub
    Else
    Analyst_input.Hide
    End If
    
    Exit Sub
    SCerr:
        MsgBox "Please Enter Sortcode", vbOKOnly, "Error"
    ACCnoerr:
        MsgBox "Please Enter Account number", vbOKOnly, "Error"
    Analysterr:
        MsgBox "Please Enter Your Name", vbOKOnly, "Error"
    End Sub
    Here you have declared Exit Sub after GoTo. But when you call GoTo then it goes to the line you declared and don't come back again unless you call them. So call exit Sub after MsgBox as below :
    Private Sub OK_Click()
    
    If AnalystName.Value = "" Then
    GoTo Analysterr
    ElseIf Sortcode.Value = "" Then
    GoTo SCerr
    ElseIf AccNo.Value = "" Then
    GoTo ACCnoerr
    Else
    Analyst_input.Hide
    End If
    
    Exit Sub
    SCerr:
        MsgBox "Please Enter Sortcode", vbOKOnly, "Error"
        Exit Sub
    ACCnoerr:
        MsgBox "Please Enter Account number", vbOKOnly, "Error"
        Exit Sub
    Analysterr:
        MsgBox "Please Enter Your Name", vbOKOnly, "Error"
        Exit Sub
    End Sub

  7. #7
    Forum Expert gmr4evr1's Avatar
    Join Date
    11-24-2014
    Location
    Texas
    MS-Off Ver
    Office 2010 and 2007
    Posts
    3,448

    Re: Userforms help

    Looks as if sanram may have resolved the issues.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Help with Userforms
    By kbern972 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-13-2014, 04:07 PM
  2. Help with vba for userforms
    By GhostCookie in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-12-2013, 09:54 PM
  3. VBA Userforms Help
    By White_Path in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 10-25-2011, 05:12 PM
  4. userforms
    By northernstar197 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-30-2007, 09:47 PM
  5. I need some help with userforms
    By T.c.Goosen1977 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-30-2006, 04:24 AM
  6. Userforms
    By Andy the yeti in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-26-2006, 12:35 PM
  7. [SOLVED] Two Userforms
    By MBlake in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-25-2005, 03:06 PM

Tags for this Thread

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