My form opens with a default name in a text box control. If the user changes the name they are prompted to change the default, or leave it like it is. The code below does not crash, and even changes the default in the form properties box - BUT when the form is closed and opened again the original default is still in the text box.
How can I change the default text and have the new default show when the form is opened again? Any suggestions would be appreciated.
-----------------
Private Sub txtMailTo_AfterUpdate()
Dim Msg, Style, Title, Response
'FormValue is global to the form and equals the string in the text box
FormValue = """" & Me.txtMailTo.Text & """"
If FormValue = Me.txtMailTo.DefaultValue Then
'If text box has not changed, do nothing
Else
'If text box has changed, ask user if this should be the new default
Msg = "Do you want to change the default to " & Me.txtMailTo.Text & "?"
Style = vbYesNo + vbQuestion + vbDefaultButton1
Title = "Change Default?"
Response = MsgBox(Msg, Style, Title)
'User chose No - do nothing
If Response = vbNo Then
DoCmd.CancelEvent
'User chose Yes - change the text box default
Else
Me.txtMailTo.DefaultValue = FormValue
DoCmd.Save acForm, "frmMain"
End If
End If
End Sub
-----------------
Private Sub Form_Unload(Cancel As Integer)
Me.txtMailTo.SetFocus
Me.txtMailTo.DefaultValue = FormValue
DoCmd.Save acForm, "frmMain"
End Sub
How can I change the default text and have the new default show when the form is opened again? Any suggestions would be appreciated.
-----------------
Private Sub txtMailTo_AfterUpdate()
Dim Msg, Style, Title, Response
'FormValue is global to the form and equals the string in the text box
FormValue = """" & Me.txtMailTo.Text & """"
If FormValue = Me.txtMailTo.DefaultValue Then
'If text box has not changed, do nothing
Else
'If text box has changed, ask user if this should be the new default
Msg = "Do you want to change the default to " & Me.txtMailTo.Text & "?"
Style = vbYesNo + vbQuestion + vbDefaultButton1
Title = "Change Default?"
Response = MsgBox(Msg, Style, Title)
'User chose No - do nothing
If Response = vbNo Then
DoCmd.CancelEvent
'User chose Yes - change the text box default
Else
Me.txtMailTo.DefaultValue = FormValue
DoCmd.Save acForm, "frmMain"
End If
End If
End Sub
-----------------
Private Sub Form_Unload(Cancel As Integer)
Me.txtMailTo.SetFocus
Me.txtMailTo.DefaultValue = FormValue
DoCmd.Save acForm, "frmMain"
End Sub