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

Change the defaultvalue of a form field

Status
Not open for further replies.

mikej336

MIS
Feb 10, 2005
164
US
I need to Change the defaultvalue of a form field and save it so that the it will have the new default value the next time I open the form. I have done this before but can't find the code.

Private Sub Form_Close()
Debug.Print Text14.Value

Dim answer

If Text14.Value <> Text14.DefaultValue Then
answer = MsgBox("Update Default Values to current Values?", vbYesNo, "Update")
If answer = 6 Then
Text14.DefaultValue = Text14.Value
Text16.DefaultValue = Text16.Value
DoCmd.Save acForm, "Start"
End If
Debug.Print Text14.DefaultValue
End If
End Sub

Thanks
Uncle Mike


 
Hi Mike,

Try something like:
Code:
With ActiveDocument
  If .FormFields("Text14").Result <> .FormFields("Text14").TextInput.Default Then
    Answer = MsgBox("Update Default Values to current Values?", vbYesNo, "Update")
    If Answer = 6 Then
      .FormFields("Text14").TextInput.Default = .FormFields("Text14").Result
      .FormFields("Text16").TextInput.Default = .FormFields("Text16").Result
      DoCmd.Save acForm, "Start"
    End If
    Debug.Print .FormFields("Text14").TextInput.Default
  End If
End With

Cheers

[MS MVP - Word]
 
Hey Macropod,

Thanks for the post but i am getting "object required" error on the line...

If .FormFields("Text14").Result <> .FormFields"Text14").TextInput.Default Then

I am putting the code in Private Sub Form_Close().

Any thoughts.

Uncle Mike
 
If the underlaying field is defined as Text:
Text14.DefaultValue = [!]Chr(34) & [/!]Text14.Value [!]& Chr(34)[/!]

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Hi Uncle Mike,

It looks like macropod has given a Word solution and you have posted an Access problem. I can't, I'm afraid, answer your question off the top of my head though - is it possible the Form needs to be opened in Design View before Design changes can be saved?

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.

Professional Office Developers Association
 
According to a web page I found the default property can only be sucessfully saved in design view.

So I came up with the idea of using custom document properties instead and just load the value at form startup.

Private Sub Form_Close()

If Me.Text14.Value <> CurrentDb.Containers ("Databases").Documents("UserDefined").Properties("ConvertTable").Value Or Me.Text16.Value <> CurrentDb.Containers("Databases").Documents("UserDefined").Properties("Outputloc").Value Then
answer = MsgBox("Update Default Values to current Values?", vbYesNo, "Update")
If answer = 6 Then
CurrentDb.Containers("Databases").Documents("UserDefined").Properties("ConvertTable").Value = Me.Text14.Value
CurrentDb.Containers("Databases").Documents("UserDefined").Properties("Outputloc").Value = Me.Text16.Value
End If
End If

End Sub

Private Sub Form_Open(Cancel As Integer)
Me.Text14.Value = CurrentDb.Containers("Databases").Documents("UserDefined").Properties("ConvertTable")
Me.Text16.Value = CurrentDb.Containers("Databases").Documents("UserDefined").Properties("Outputloc")
End Sub

Thanks

Uncle Mike
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top