+ Reply to Thread
Results 1 to 7 of 7

userForm assigning values

Hybrid View

bstubbs userForm assigning values 07-29-2009, 10:05 AM
romperstomper Re: userForm assigning values 07-29-2009, 10:09 AM
bstubbs Re: userForm assigning values 07-29-2009, 10:19 AM
romperstomper Re: userForm assigning values 07-29-2009, 10:25 AM
bstubbs Re: userForm assigning values 07-29-2009, 10:54 AM
romperstomper Re: userForm assigning values 07-29-2009, 11:10 AM
bstubbs Re: userForm assigning values 07-29-2009, 12:15 PM
  1. #1
    Forum Contributor
    Join Date
    01-09-2009
    Location
    Cedar Hill, Tx
    MS-Off Ver
    Excel 2003
    Posts
    200

    userForm assigning values

    Howdy, again:

    When starting up my UserForm, I'm trying to set a value within a listBox, using a command like userForm1.lbSelectDriver.value = "Bob". That selection is within the list data so the listBox shows "Bob" when the form is displayed. However, to make the selection "valid", it seems that I have to enter the listBox and "jiggle" the selection (move the cursor to a different selection and then back to the one I want). Should I be setting the desired value on the basis of listIndex? If so, how?

    Any thoughts.

    TIA.

    Bob
    Last edited by bstubbs; 07-29-2009 at 12:44 PM.

  2. #2
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,998

    Re: userForm assigning values

    Where exactly are you using that code?
    Everyone who confuses correlation and causation ends up dead.

  3. #3
    Forum Contributor
    Join Date
    01-09-2009
    Location
    Cedar Hill, Tx
    MS-Off Ver
    Excel 2003
    Posts
    200

    Re: userForm assigning values

    I load the userForm, set the values that I want and then show. Is that what you mean?

    Bob

  4. #4
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,998

    Re: userForm assigning values

    It was the specific code I was after really. From what you describe, it ought to work.

  5. #5
    Forum Contributor
    Join Date
    01-09-2009
    Location
    Cedar Hill, Tx
    MS-Off Ver
    Excel 2003
    Posts
    200

    Re: userForm assigning values

    Here's the code:

    Sub editRecord()
        Load UserForm1
        UserForm1.tbEditNew = "Edit"
        UserForm1.txtDate = ActiveCell.Value
        Select Case ActiveCell.Offset(0, 3).Value
            Case "Cedar Hill"
                UserForm1.selectCedarHill = True
                UserForm1.selectDeSoto = False
                UserForm1.selectLancaster = False
            Case "DeSoto"
                UserForm1.selectCedarHill = False
                UserForm1.selectDeSoto = True
                UserForm1.selectLancaster = False
            Case "Lancaster"
                UserForm1.selectCedarHill = False
                UserForm1.selectDeSoto = False
                UserForm1.selectLancaster = True
        End Select
        Select Case ActiveCell.Offset(0, 8)
            Case "AM only"
                UserForm1.obAMonly = True
                UserForm1.obAMPM = False
                UserForm1.obPMonly = False
            Case "AM / PM"
                UserForm1.obAMonly = False
                UserForm1.obAMPM = True
                UserForm1.obPMonly = False
            Case "PM only"
                UserForm1.obAMonly = False
                UserForm1.obAMPM = False
                UserForm1.obPMonly = True
        End Select
        UserForm1.lbSelectDriver.Value = ActiveCell.Offset(0, 2)
        driverID = ActiveCell.Offset(0, 1)
        If ActiveCell.Offset(0, 9) <> "" Then
            UserForm1.lbReasons.Value = ActiveCell.Offset(0, 9)
        End If
        If ActiveCell.Offset(0, 10) <> "" Then
            UserForm1.lbSelectStandbyAM.Value = ActiveCell.Offset(0, 10)
        End If
        If ActiveCell.Offset(0, 11) <> "" Then
            UserForm1.lbSelectStandbyMD.Value = ActiveCell.Offset(0, 11)
        End If
        If ActiveCell.Offset(0, 12) <> "" Then
            UserForm1.lbSelectStandbyPM.Value = ActiveCell.Offset(0, 12)
        End If
        If ActiveCell.Offset(0, 13) <> "" Then
            UserForm1.lbSelectStandbyOther.Value = ActiveCell.Offset(0, 13)
        End If
        UserForm1.Show
    End Sub
    I'm pulling a "record" from the worksheet, putting the data into the userForm and allowing the user to further edit the data.

    Bob

  6. #6
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,998

    Re: userForm assigning values

    Do any of the listboxes work properly? Do their change events affect each other? Are they bound to ranges on the worksheet?

  7. #7
    Forum Contributor
    Join Date
    01-09-2009
    Location
    Cedar Hill, Tx
    MS-Off Ver
    Excel 2003
    Posts
    200

    Re: userForm assigning values

    In looking at which fields come over ok and those that didn't, there was nothing in the listBox definitions that would cause some to work and some not. I changed the code, however, to first "setFocus" and then setting the desired value and it worked fine, consistently. Although this solves the problem, should that point me in some direction as to why some worked and some didn't?

    Thanks.

    Bob

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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