+ Reply to Thread
Results 1 to 3 of 3

How to limit the action of CommadButton

  1. #1
    Registered User
    Join Date
    05-06-2012
    Location
    Lisbon,Portugal
    MS-Off Ver
    Excel 2010
    Posts
    79

    How to limit the action of CommadButton

    I have a userform vba in which I put information, in combobox and textbox, and it operates through a commandbutton to be forwarded in the worksheets.This procedure is preceded by code in the Modulo below.
    (whenever I make a launch automatically it change order the number in worksheet).

    Sub Macro1()
    ' Macro1 Macro
    '
    Range("A2").Select
    ActiveCell.FormulaR1C1 = "nš"
    Range("A3").Select
    End Sub
    ====xx============
    Private Sub cboMes_Change()
    Dim Num As Range

    Set Num = Sheets(cboMes.Value).Cells(Rows.Count, "A").End(xlUp).Offset(0, 0)
    If Num = "nš" Then txtOrd = 1
    If Num <> "nš" Then txtOrd = Num + 1
    End Sub
    aaaaaaaaaaaaaaaaaaaaa
    The question is:
    How to enter a code after to click on the CommandButton, so that it fails to launch into worksheet, without the information of all the boxes, as well as don't fill the order number on worksheet?
    I already tried the use, of all kind of events and it didn't results: ex
    if combobox.value="" and textbox.value=" then
    msgbox("xxx")
    end if

    Thanks for all

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: How to limit the action of CommadButton

    What controls do you have on the userform?

    You can check if a texbox is empty using Textbox1.Value ="" and to check if anything is selected in a combobox you can check it's ListIndex property - if it's -1 nothing has been selected.

    Can you attach a sample workbook?

    PS When you post code please remember to add code tags - makes it easier to read and copy.
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    05-06-2012
    Location
    Lisbon,Portugal
    MS-Off Ver
    Excel 2010
    Posts
    79

    Re: How to limit the action of CommadButton

    Quote Originally Posted by Norie View Post
    What controls do you have on the userform?

    You can check if a texbox is empty using Textbox1.Value ="" and to check if anything is selected in a combobox you can check it's ListIndex property - if it's -1 nothing has been selected.

    Can you attach a sample workbook?

    PS When you post code please remember to add code tags - makes it easier to read and copy.
    Hi Norie
    Thanks for your patience
    I took time to get a sample without the result that I wanted, that's why I took time for answer you.
    But, I think that I didn't explain it well.
    My goal that I set in question is:
    In the event of failing to fill a combobox or a textbox when I click to record in the worksheet, the system shows a Msg (vb msg) to call attention “Please, complete the form” and do not record until everything is completed.
    This has now managed to overcome with (.. if .. then .. msg ..), what I meant is that after giving the "ok" the system does not delete the boxes already filled, and let you fill in the missing before being released in the worksheet
    Private Sub CmdAdd_click()
    Dim rng As Range
    ' Attention mensages

    If cboMonth.Value = "" Then
    MsgBox ("Please, Complete de Userform")

    ElseIf cbo1.Value <> "" And Cbo2.Value <> "" And txt1.Value <> "" And Txt2.Value <> "" Then
    Set rng = Sheets(cboMonth.Value).Cells(Rows.Count, "A").End(xlUp).Offset(1, 0)
    rng = txtOrd.Value
    rng.Offset(0, 2) = cbo1
    rng.Offset(0, 3) = Cbo2
    rng.Offset(0, 4) = txt1.value
    rng.Offset(0, 5) = Txt2.Value
    ‘record order in worksheet
    txtOrd.Value = txtOrd.Value + 1
    rng.Offset(0, 1) = txtDat2.Value

    End If

+ 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