Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Set text entered into a form textbox as default value

Status
Not open for further replies.

iojbr

Technical User
Feb 12, 2003
129
US
Hi:

How do I use vba to set the current text entered into an unbound form's textbox (txt1) as that control's default value so when I close and open the form again, that value will be the one appears in that textbox. I tried using the after update property of the textbox in question, and using Me.txt1.default Value = Me.txt1.text, but it's not working. Thanks.
 
The only way the default value will stick is if your form is saved while in design view. You could also use code to save the default to a table and then retrieve the value when the form opens.

Code:
Private Sub Form_Open(Cancel As Integer)
   [COLOR=#4E9A06]'assuming txt1 is a string value[/color]
    Me.txt1.DefaultValue = """" & DLookup("Default", "tblDefaults", "FormName = 'MyFormName' AND CtrlName='txt1'") & """"
End Sub

Duane
Hook'D on Access
MS Access MVP
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top