Results 1 to 3 of 3
  1. #1
    New Lounger
    Join Date
    Nov 2001
    Location
    London
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Building Userforms (97)

    I am building a runtime userform where the controls are added dynamically. The form builds a list of records from a recordset (see below)

    For intClass = 1 To intRecs
    curDiffernce = mrsConflicts.Fields("debt") - mrsConflicts.Fields("woff")
    If curDiffernce < -1 Or curDiffernce > 1 Then

    intLeft = 20
    intTop = intTop + 20
    'Buyer
    With Me.Controls.Add(bstrprogid:="forms.textbox.1")
    .Left = intLeft
    .Width = intWidth * 10
    .Height = intHeight
    .Top = intTop
    .Value = mrsConflicts.Fields("buyr_short_name")
    .Locked = True
    intLeft = intLeft + .Width + intWidth
    End With

    'Advter
    With Me.Controls.Add(bstrprogid:="forms.textbox.1")
    .Left = intLeft
    .Width = intWidth * 10
    .Height = intHeight
    .Top = intTop
    .Value = mrsConflicts.Fields("advt_short_name")
    .Locked = True
    intLeft = intLeft + .Width + intWidth
    End With
    With Me.Controls.Add(bstrprogid:="forms.checkbox.1")
    .Left = intLeft
    .Width = intWidth
    .Height = intHeight
    .Top = intTop
    .Value = True
    .Locked = False
    intLeft = intLeft + .Width + intWidth
    .Click = "changeValue"
    End With


    I would like an event procedure to run when I click the check box. However the above code .click property does not work, nor does, .afterUpdate (i've tried all sorts of variations)

    As I don't know which checkbox the user is clicking - as the number of check boxes will depend on the number of records in my recordset, how do I write an event that handles what happens when that check box is clicked?

    Any suggestions more than welcome

    Amanda

  2. #2
    WS Lounge VIP sdckapr's Avatar
    Join Date
    Jul 2002
    Location
    Pittsburgh, Pennsylvania, USA
    Posts
    11,225
    Thanks
    14
    Thanked 342 Times in 335 Posts

    Re: Building Userforms (97)

    [Modified to add some code]

    Perhaps I am missing what you are trying to do, but it seems that you are trying to simulate a listbox with multiple selections.

    Why don't you just add items to a listbox and not add additional textboxes and checkboxes? The coding should be easier. Just have one button to trigger when you want to act on all the selections.

    Here is an example (again, if I understand what you are doing). All the code isn't there so I had to guess at some things). You must create a listbox (named Listbox1 or change the code) on the form. I have it 2 columns with a checkbox, but that can be changed.

    Steve

    <pre>Dim intRows As Integer
    intRows = 0

    ReDim myArray(2, intRecs - 1)

    For intclass = 0 To intRecs - 1 'this is changed, array start with 0
    curDiffernce = mrsConflicts.Fields("debt") - mrsConflicts.Fields("woff")
    If curDiffernce < -1 Or curDiffernce > 1 Then

    'Fills the array from recordset
    myArray(0, intRows) = mrsConflicts.Fields("buyr_short_name")
    myArray(1, intRows) = mrsConflicts.Fields("advt_short_name")
    intRows = intRows + 1 'counts the items, since you do not use all of intRecs!
    'endif
    Next

    'shrink the array, preserving the values to get rid of "blanks"
    'The array could have blanks due to the "if curDiffernce... " statment
    ReDim Preserve myArray(2, intRows - 1)

    'Populate the listbox
    With ListBox1
    .ColumnCount = 2
    .MultiSelect = fmMultiSelectExtended
    .ListStyle = fmListStyleOption
    .Column() = myArray
    End With

    End Sub
    </pre>


  3. #3
    New Lounger
    Join Date
    Nov 2001
    Location
    London
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Building Userforms (97)

    For any one who is interested I found this website had the answer to my question

    http://j-walk.com/ss/excel/tips/tip44.htm edited by Rory to make link live.

Posting Permissions

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