+ Reply to Thread
Results 1 to 2 of 2

unresponsive command button

  1. #1
    Registered User
    Join Date
    04-30-2008
    Posts
    1

    unresponsive command button

    hi,

    i'm programming some sort of analysis system in vba, and I'm having one remaining issue I can't seem to resolve. I have a dynamic form with comboboxes. The last entry on the form is a commandbutton to close the UserForm. Everything shows up nicely, however, clicking is unresponsive with the below code. When I add a physical commandbutton to the Userform and attach the same "GenderOK_click" code to it, it does work.

    Any suggestions on where the mistake is are more than welcome !

    Thanx,
    Weyer


    Sub UserForm_Activate()
    Dim txtBox As MSForms.Label
    Dim rngFields As Excel.Range
    Dim field As Excel.Range
    Dim lngNextTop As Long
    Dim lngTitleBarHeight As Long
    Dim GenderOK As MSForms.CommandButton

    Const cTextBoxHeight As Long = 18
    Const cTextBoxWidth As Long = 30
    Const cGap As Long = 4

    Set rngFields = Excel.Range("Samples")

    lngTitleBarHeight = Me.Height - Me.InsideHeight

    lngNextTop = cGap

    For Each field In rngFields
    If field.Value <> "" Then
    Set txtBox = Me.Controls.Add("Forms.Label.1", "txt")


    txtBox.Caption = field.Value
    txtBox.Left = cGap
    txtBox.Top = lngNextTop + 4
    txtBox.Height = cTextBoxHeight
    txtBox.Width = cTextBoxWidth
    txtBox.Font.Size = 8
    txtBox.Font.Bold = True

    Set ComboBox1 = Me.Controls.Add("Forms.ComboBox.1", "Gender")
    With ComboBox1
    .AddItem "Male"
    .AddItem "Female"
    .AddItem "Unknown"
    .Left = txtBox.Width + cGap + 8
    .Top = lngNextTop
    .Height = cTextBoxHeight
    .Width = 70
    .Font.Size = 8
    .Font.Bold = False
    .ControlSource = Cells(field.row, field.column + 2).Address
    End With


    lngNextTop = lngNextTop + cTextBoxHeight + cGap

    Me.Height = lngNextTop + lngTitleBarHeight
    End If
    Next field

    Set txtBox = Nothing
    Set GenderOK = Me.Controls.Add("Forms.CommandButton.1", "GenderOK")
    With GenderOK
    .Top = lngNextTop + 5
    .Left = 42
    .Width = 40
    .Caption = "OK"
    .Font.Size = 10
    .Font.Bold = True
    .Height = 20
    End With

    Me.Height = lngNextTop + 28 + lngTitleBarHeight
    End Sub


    Sub GenderOK_Click()
    Range("G17").Value = "Sample genders set !"
    Unload Me ' Close the form
    End Sub

  2. #2
    Valued Forum Contributor mudraker's Avatar
    Join Date
    11-10-2003
    Location
    Melbourne, Australia
    Posts
    3,983
    UserForm_Activate would run only when the form is activated not by clicking on the form or are you refering to clicking on something else

    If you are wanting the code to run when you click on the form & not a specific button on the form you will ed to use a UserForm_Click macro
    Please Read Forum Rules Before Posting
    Wrap VBA code by selecting the code and clicking the # icon or Read This
    How To Cross Post politely

    Top Excel links for beginners to Experts

    If you are pleased with a member's answer then use the Scales icon to rate it
    If my reply has assisted or failed to assist you I welcome your Feedback.

+ 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