+ Reply to Thread
Results 1 to 3 of 3

Make textbox1.value default

  1. #1
    Dr.Schwartz
    Guest

    Make textbox1.value default

    I have a form that contains a textbox. How can I make the entered value
    appear in the textbox the next time the form is opened? As in I would like to
    be able to control the default value of the textbox.

    Thanks
    The Doctor

  2. #2
    Tom Ogilvy
    Guest

    Re: Make textbox1.value default

    Bob Phillips answered a similar question just now:

    David,

    The method that I use is a hidden worksheet. Store the values when the form
    is unloaded, then retrieve them when the form is re-loaded.

    There are many alternatives, use the registry, a text file, or even Excel
    names, but a hidden worksheet is the simplest IMO.

    Sample code

    Private Sub UserForm_Initialize()
    With Worksheets("SavedValues")
    Me.TextBox1.Text = .Range("A1").Value
    If .Range("A2").Value <> "" Then
    Me.ListBox1.ListIndex = .Range("A2").Value
    End If
    End With
    End Sub

    Private Sub UserForm_Terminate()
    With Worksheets("SavedValues")
    .Range("A1").Value = Me.TextBox1.Text
    .Range("A2").Value = Me.ListBox1.ListIndex
    End With

    End Sub


    --
    HTH

    Bob Phillips



    --
    Regards,
    Tom Ogilvy

    "Dr.Schwartz" <[email protected]> wrote in message
    news:[email protected]...
    > I have a form that contains a textbox. How can I make the entered value
    > appear in the textbox the next time the form is opened? As in I would like

    to
    > be able to control the default value of the textbox.
    >
    > Thanks
    > The Doctor




  3. #3
    Dr.Schwartz
    Guest

    Re: Make textbox1.value default

    Thanks Tom and Bob, just what I was looking for.

    The Doctor

    "Tom Ogilvy" wrote:

    > Bob Phillips answered a similar question just now:
    >
    > David,
    >
    > The method that I use is a hidden worksheet. Store the values when the form
    > is unloaded, then retrieve them when the form is re-loaded.
    >
    > There are many alternatives, use the registry, a text file, or even Excel
    > names, but a hidden worksheet is the simplest IMO.
    >
    > Sample code
    >
    > Private Sub UserForm_Initialize()
    > With Worksheets("SavedValues")
    > Me.TextBox1.Text = .Range("A1").Value
    > If .Range("A2").Value <> "" Then
    > Me.ListBox1.ListIndex = .Range("A2").Value
    > End If
    > End With
    > End Sub
    >
    > Private Sub UserForm_Terminate()
    > With Worksheets("SavedValues")
    > .Range("A1").Value = Me.TextBox1.Text
    > .Range("A2").Value = Me.ListBox1.ListIndex
    > End With
    >
    > End Sub
    >
    >
    > --
    > HTH
    >
    > Bob Phillips
    >
    >
    >
    > --
    > Regards,
    > Tom Ogilvy
    >
    > "Dr.Schwartz" <[email protected]> wrote in message
    > news:[email protected]...
    > > I have a form that contains a textbox. How can I make the entered value
    > > appear in the textbox the next time the form is opened? As in I would like

    > to
    > > be able to control the default value of the textbox.
    > >
    > > Thanks
    > > The Doctor

    >
    >
    >


+ 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