vba: userform text box...set default text to a variable?

  • Thread starter Thread starter snsyg
  • Start date Start date
S

snsyg

i have a user form set up with three text boxes. if the user has opene
the dialog box and entered the data once, then re-opens the dialog bo
again to make any updates, i want the previosly entered data to appea
as the default (the first time the user opens it i want all the tex
boxes blank).

there is a property called "text" for the user form and i can ente
text there manually that shows up as the default. the problem is tha
the text is a variable from project to project and there is n
consistant initial default i can use.

in the vba code for the ok button in the dialog box (the last piece o
code before the code for unloading the dialog box, i wrote:
ProjectName.Text = "Acme Hardware". the code executes without error
but does not display "Acme Hardware" as the default in the text box th
next time i open the dialog box.

in the vba code for the button the shows the dialog box, i tried
ProjectName.Text = "Ace Hardware", but i get an error.

any ideas or help would be greatly appreciated!

thanks

kare
 
Hi Karen

If the textbox information is put into the sheet you could
grab these in a form_initialize macro
Textbox1.Text = range(lastrow,column1)
textbox2.Text = range(lastrow,column2) just a number for
columns.

VB can't hold dynamic variables once the procedure is run
so you'll have to get them from the worksheet.

Regards
Peter
 
hi peter,

i figured out the problem before i read your pos, but you are correct.
it was a syntax error on my part. i did not realize i had to put the
name of the userform together with the name of the text box and
variable. i also figured out that i need to load the user form, then
check for any prior entries (that were stored in a cell called
"ProjectNameStorage), before showing the user form.

here's a condensed version of what i did, in case you are interested:

Private Sub ProjectDataButton_Click()
'
'Load Project Data Input Dialog Box and Load Previously Input Data
Load uf_Project_Data_Input
'
If Range("ProjectNameStorage") = "" Then
uf_Project_Data_Input.tbDate.Text = ""
ElseIf Range("ProjectNameStorage") <> "" Then
uf_Project_Data_Input.tbProjectName.Text =
Range("ProjectNameStorage")
End If
'
'Show Project Data Input Dialog Box
uf_Project_Data_Input.Show
'
End Sub

works like a charm.

thanks for your reply

karen
 
Back
Top