+ Reply to Thread
Results 1 to 10 of 10

Waiting for Input

Hybrid View

  1. #1
    Registered User
    Join Date
    12-08-2009
    Location
    Madison, WI
    MS-Off Ver
    Excel 2003
    Posts
    30

    Waiting for Input

    On the SetNum sheet is an ordered list of data sets. (the first set is set 0) The data itself is stored on a different sheet (Data). I would like the user to click the ModifySet button, enter a number, and have the form pop up with the previously entered data.

    The SetNum control is an invisible label used for tracking the current set number. Its default value is 0.

    The code for the button:

    Private Sub ModifySet_Click()
    
    SetForm.SetNum.Caption = InputBox("Please Enter Set Number", "Count Request Wizard")
    
    If SetForm.SetNum.Caption > 0 And SetForm.SetNum.Caption <= WorksheetFunction.Max(Worksheets("SetNum").Range("B:B")) Then
        Debug.Print "Test " & SetForm.SetNum.Caption
        SetForm.Show
    Else
        MsgBox ("Sorry, set number not valid.")
    End If
    
    End Sub
    In theory, this is what should be pulling of the previous data entered. All of the controls have a corresponding named column in "Data". On Error is included since not all controls (such as labels) need/have their own column.

    Private Sub UserForm_Initialize()
    
    On Error Resume Next
    
    Debug.Print "Int " & SetForm.SetNum.Caption
    
    For Each Control In SetForm.Controls
        Name = Control.Name
        Control.Value = Worksheets("Data").Cells(SetForm.SetNum.Caption + 2, Worksheets("Data").Range(Name).Column).Value
    Next Control
    
    End Sub
    Here is what I get from the two Debug.Print commands.

    Int 0
    Test 1
    What I get is the UserForm coming up after I've input the SetNum with a SetNum.Caption of the correct value, but the data is always from Set0 (the default value for SetNum.Caption)

    Am I just overlooking something?

    Thanks,
    Magness
    Last edited by magness; 01-14-2010 at 04:32 PM.

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Waiting for Input

    Hello Magness,

    You are attempting to assign values to the UserForm before the UserForm has been loaded into memory. The Show command loads the UserForm into memory and then displays it. The Load command will place the UserForm into memory but not display the form. This allows for the properties and variables on the sheet to be set before displaying the form.
    Private Sub ModifySet_Click()
    
    Load SetForm
    
    SetForm.SetNum.Caption = InputBox("Please Enter Set Number", "Count Request Wizard")
    
    If SetForm.SetNum.Caption > 0 And SetForm.SetNum.Caption <= WorksheetFunction.Max(Worksheets("SetNum").Range("B:B")) Then
        Debug.Print "Test " & SetForm.SetNum.Caption
        SetForm.Show
    Else
        MsgBox ("Sorry, set number not valid.")
    End If
    
    End Sub
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Registered User
    Join Date
    12-08-2009
    Location
    Madison, WI
    MS-Off Ver
    Excel 2003
    Posts
    30

    Re: Waiting for Input

    I had tried this (and did so again just now), but get the same results.


    My button for adding a new set has this:

    Private Sub AddSet_Click()
    
    SetForm.SetNum.Caption = Cells(Worksheets("SetNum").Cells.SpecialCells(xlCellTypeLastCell).Row, 2) + 1
    SetForm.Show
    
    End Sub
    And the set number is passing to label caption without Load SetForm here.

    Would Load SetForm let me refer to controls without adding the SetFrom. to the front?

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Waiting for Input

    Hello Magness,

    You should post your workbook for review.

  5. #5
    Registered User
    Join Date
    12-08-2009
    Location
    Madison, WI
    MS-Off Ver
    Excel 2003
    Posts
    30

    Re: Waiting for Input

    Here you go. Thanks for taking a look at it. I apologize in advance for my naming conventions (or lack there of).
    Attached Files Attached Files

  6. #6
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Waiting for Input

    Hello Magness,

    I moved the variable "SetNum" from the General Declarations section of the UserForm to the top of Module1. This way it is visible to all parts of the project code as long as VBA is running.
    Option Explicit
    
    Public SetNum As Integer
    
    Sub FormTtest()
        SetForm.Show
    End Sub
    
    Sub NameColumns()
    
    Dim Name As String
    Dim X As Integer
    Dim N As Name
    
    For Each N In Names
        N.Delete
    Next
    
    For X = 1 To 256
        If Cells(1, X).Value <> "" Then
            Name = Cells(1, X).Value
            Debug.Print Name
            Range(Cells(1, X), Cells(65536, X)).Name = Name
        End If
    Next X
    
    End Sub
    Attached Files Attached Files

+ 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