Results 1 to 4 of 4
  1. #1
    Sidran is offline Novice
    Windows 8 Access 2013
    Join Date
    Jul 2014
    Posts
    18

    Make a text box retain its previous value

    I have a text box in a form. When the value in the text box is changed, a message box appears asking if the user wants to change the value in the text box. If they select "Yes", all is good and it goes on well, but when they select "No" is it possible for the text box to retain its previous value?

    For example.



    The value in the text box is "1". The user changes this value to "2". A message box pops up asking if the user wants to change the value, the user select "No" and so the value in the text box goes back to "1", the number it started with before it changed.

  2. #2
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 7 32bit Access 2003
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,537
    Can you show us the code you have that shows the message box and tell us which event it is in.
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  3. #3
    Sidran is offline Novice
    Windows 8 Access 2013
    Join Date
    Jul 2014
    Posts
    18
    reply = MsgBox("Do you want to change the invoice number", vbYesNo, "Change invoice number")
    If reply = vbYes Then
    DoCmd.SetWarnings False
    DoCmd.OpenQuery "Invoicing Hidden Table2 Query", acViewNormal, acEdit
    DoCmd.OpenQuery "Invoicing Query5", acViewNormal, acEdit
    DoCmd.SetWarnings True
    End If
    If reply = vbNo Then
    Me.Text9 = ""


    That is the code written in the After Update Event. Ignore the 2 queries as they are just 2 update queries that I wish to run when the user selects "Yes". If the reply is "No" instead of Text9 being an empty field, I want it to show the previous value.

  4. #4
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 7 32bit Access 2003
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,537
    Try the following code in the Before Update event instead of the After Update event:
    Code:
    If  MsgBox("Do you want to change the invoice number", vbYesNo, "Change invoice number")= vbYes Then
      DoCmd.OpenQuery "Invoicing Hidden Table2 Query", acViewNormal, acEdit
      DoCmd.OpenQuery "Invoicing Query5", acViewNormal, acEdit
    Else
      Cancel = True
      Me.Text9.Undo
    End If
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 7
    Last Post: 07-20-2013, 03:59 AM
  2. Replies: 5
    Last Post: 06-18-2013, 12:53 PM
  3. Replies: 1
    Last Post: 09-07-2011, 09:22 AM
  4. Replies: 2
    Last Post: 05-05-2010, 02:52 PM
  5. Replies: 12
    Last Post: 08-09-2009, 07:35 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums