VBA: 2 VBA Questions

  • Hello Everyone:


    I have two questions regarding VBA.


    1. When using a textbox on a userform, if the person does not enter information how do I stop the userform from proceeding? I know that I can add a message box that says “please enter name’ or whatever but if the user hits the ok button my userform just proceeds to the next userform when really I don’t want this to move on without the information in the textbox.


    2. If I have a combobox and the user picks one of the categories how do I change the font colour for all categories that meet this requirement? For example, I have ten choices that all have four attributes the combobox allows you to select an attribute after that the combobox is selected and I want to be able to change the font colour for all categories that met this specific attribute.


    Hope this is clearly explained. I am kind of in over my head. In advance I would like to thank everyone for their assistance. This website has been a godsend.


    Cheers,
    Jason

  • Hi Jason,


    In response to the first question.
    This is the code for a userform with a textbox and button.
    If the textbox is empty then e message is displayed.

    Code
    1. Private Sub CommandButton1_Click()
    2. Unload Me
    3. End Sub
    4. Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
    5. If TextBox1.Text = "" Then
    6. MsgBox "Please complete textbox1"
    7. Cancel = 1
    8. End If
    9. End Sub


    The second part is a little confusing.
    Maybe you could try a explain a little further.


    A combobox can not have differently coloured items in its list, if this is what you are trying to do.


    Cheers
    Andy

    [h4]Cheers
    Andy
    [/h4]

  • Andy,


    Thank you for your help. The first suggestion worked like a charm.


    As for the second quetion. What I have is one userform that populates several cells. Depending on the department selected it will have around five to ten people. There will be a time, day, and couple other pieces of information that corresponds with that name. Then my second userform allows me to sort by time. Then I want the third userform to allow me to highlight (change font colour) for all people that have the selected day.


    Once again thank you for your help.


    Cheers,
    Jason

  • Hi Jason,


    In order to display a list with different font attributes you will need to use a different control.


    It maybe possible to use the Listview control.
    Not sure whether Listview is available to all, or just those with Visual Studio installed.
    On the toolbox rightclick and choose Additional Controls...
    See if Microsoft Listview is available.


    If not you may have to use checkboxes for each name.


    If you need help with either of the above suggestions post back.


    Cheers
    Andy

    [h4]Cheers
    Andy
    [/h4]