ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   User Forms (https://www.excelbanter.com/excel-programming/329722-user-forms.html)

Gilly Hampshire

User Forms
 
Could some one please help. I am trying to create a user form that will
enter data into an Excel spreadsheet. I have managed to do this but I want 2
of the text boxes to remeber what was last entered into them. I have managed
this if I hide the form but when I close the spreadsheet and reopen the form
has now lost the information. What can I do to prevent this happening!!!
--
Thanks

Gilly

Jim Rech

User Forms
 
Same concept as Chandra but if you're writing the entries in the textboxes
to a worksheet (and presumably saving it) then in the userform's initialize
event you can write code to reverse the process. That is, write the cell
contents to the textboxes.

--
Jim
"Gilly Hampshire" wrote in
message ...
| Could some one please help. I am trying to create a user form that will
| enter data into an Excel spreadsheet. I have managed to do this but I
want 2
| of the text boxes to remeber what was last entered into them. I have
managed
| this if I hide the form but when I close the spreadsheet and reopen the
form
| has now lost the information. What can I do to prevent this happening!!!
| --
| Thanks
|
| Gilly



Bob Phillips[_7_]

User Forms
 
Write the data to a hidden worksheet cell in the userform close event, and
restore it in the workbook_open,

In the userform

Private Sub UserForm_Terminate()
With Worksheets("formdata")
.Range("A1").Value = TextBox1.Text
.Range("A2").Value = TextBox2.Text
End With
End Sub

and in the Thisworkbook code module

Private Sub Workbook_Open()
With Worksheets("formdata")
Load UserForm1
UserForm1.TextBox1.Text = .Range("A1").Value
UserForm1.TextBox2.Text = .Range("A2").Value
End With
End Sub

'This is workbook event code.
'To input this code, right click on the Excel icon on the worksheet
'(or next to the File menu if you maximise your workbooks),
'select View Code from the menu, and paste the code



--
HTH

Bob Phillips

"Gilly Hampshire" wrote in
message ...
Could some one please help. I am trying to create a user form that will
enter data into an Excel spreadsheet. I have managed to do this but I

want 2
of the text boxes to remeber what was last entered into them. I have

managed
this if I hide the form but when I close the spreadsheet and reopen the

form
has now lost the information. What can I do to prevent this happening!!!
--
Thanks

Gilly




James Cox[_2_]

User Forms
 
Essentially the same suggestion as several of the above - but how about
using a rangeless named range?

Check the Excel help item titled "Creat a name to represent a formula or a
constant"

In your VBA code, you can store the value with something line

Range("TxtBoxA").Value = me.TxtBoxA.Text

and upon opening your form, you can retrieve it with

me.TxtBoxA.Text = Range("TxtBoxA").Value

Less chance of the casual user "helpfully" changing a worksheet cell for
you...

James Cox

"Gilly Hampshire" wrote in
message ...
Could some one please help. I am trying to create a user form that will
enter data into an Excel spreadsheet. I have managed to do this but I

want 2
of the text boxes to remeber what was last entered into them. I have

managed
this if I hide the form but when I close the spreadsheet and reopen the

form
has now lost the information. What can I do to prevent this happening!!!
--
Thanks

Gilly





All times are GMT +1. The time now is 02:07 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com