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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

changing a default value with a command button

Status
Not open for further replies.

cayden2007

Technical User
Mar 19, 2007
22
US
I want to place a command button on a form and be able to change the default value of a field using the command button.

Is there an easy way to do this?

Please help.

Thanks,
Jerome
 
Code:
Private Sub Command11_Click()
 Dim strFormName As String
 Dim strDefault As String
 strDefault = InputBox("Enter default")
 strFormName = Me.Name
 DoCmd.OpenForm strFormName, acDesign
 Forms(strFormName).strLastName.DefaultValue = "'" & strDefault & "'"
 DoCmd.SetWarnings (False)
 DoCmd.Save acForm, strFormName
 DoCmd.OpenForm strFormName
End Sub
 
Opening in design view allows the change to be permanent. If the change is temporary then do not open in design just comment out this line
' DoCmd.OpenForm strFormName, acDesign
 
I am trying to figure out what I change in this code for it work for me.

I changed this line:
Code:
Forms(strFormName).strLastName.DefaultValue = "'" & strDefault & "'"

to

Code:
Forms(strFormName).strPayment.DefaultValue = "'" & strDefault & "'"[code]

I am getting this error:  Run time error 2465 - Application-defined or object defined error

What am I doing wrong?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top