Results 1 to 12 of 12
  1. #1
    Join Date
    Aug 2011
    Location
    Richmond, VA
    Posts
    38

    Unanswered: Data Entry Form Question 1

    I have serveral questions, but let's take one at a time.

    1. How do I force the user to click the Save Record button? I want some code to run before it flips to a new record when the last text box is filled. The Before Update event is causing me some grief and I don't want to use that if possible.

    Thanks,

    Paul

  2. #2
    Join Date
    Apr 2005
    Location
    Zagreb - Croatia
    Posts
    372
    Look at "DemoSaveA2000.mdb" (attachment, zip).
    Open Form1 and try to enter a new record,
    or to change an old record.
    You dont need a button for this.
    Look at VBA. There is a difference
    between "Form_BeforeUpdate" and "Field_BeforeUpdate".
    Attached Files Attached Files

  3. #3
    Join Date
    Aug 2011
    Location
    Richmond, VA
    Posts
    38
    Hi, thanks. When I try to open your zip file it says it is not a valid archive. The file size is very small. Could you check it and attach it again?

  4. #4
    Join Date
    Apr 2005
    Location
    Zagreb - Croatia
    Posts
    372
    Here it is. (attachment, zip).
    Attached Files Attached Files

  5. #5
    Join Date
    Aug 2011
    Location
    Richmond, VA
    Posts
    38
    Sadly, I cannot open it.

  6. #6
    Join Date
    Apr 2005
    Location
    Zagreb - Croatia
    Posts
    372
    It is Access2000, which Access you have got ??

  7. #7
    Join Date
    Aug 2011
    Location
    Richmond, VA
    Posts
    38
    I have 2010, but the problem is when I open the zip file. It says it is not a valid archive. I can't even get to the db

  8. #8
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    Did you add DbForums in the Safe Sites list of your browser and/or firewall?
    Have a nice day!

  9. #9
    Join Date
    Aug 2011
    Location
    Richmond, VA
    Posts
    38
    Not sure how or if I can as a guest at this company. Seems like I've downloaded zips before, but I can't prove it.
    Last edited by paxham; 10-14-11 at 12:07. Reason: typo

  10. #10
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    OK. The code of the form module in the database provided by MStef-ZG is:
    Code:
    Option Compare Database
    Option Explicit
    
    Private Sub Form_BeforeUpdate(Cancel As Integer)
    If Me.Dirty Then
      If MsgBox("Do you want to SAVE the record (or the change)", vbYesNo, "???????") = vbNo Then
            Me.Undo
            Cancel = True
            Me.Client.SetFocus
      End If
    End If
    
    End Sub
    
    Private Sub Form_Current()
        Me.Client.SetFocus
    End Sub
    
    Private Sub Form_Error(DataErr As Integer, Response As Integer)
      If DataErr = 2169 Then
         Response = acDataErrContinue
         Exit Sub
      End If
    End Sub
    Where Client is a TextBox.
    Have a nice day!

  11. #11
    Join Date
    Aug 2011
    Location
    Richmond, VA
    Posts
    38
    OK, I had to sweat through this, but I got it.

    I took all my codes out of the Save Record button and place it in the Else portion of the If statement. The only code left on my button is DoCmd****nCommand acCmdSaveRecord which triggers the Before Update event.

    Code:
    If Me.Dirty Then
      If MsgBox("Do you want to SAVE the record (or the change)", vbYesNo + vbDefaultButton2, "???????") = vbNo Then
          Cancel = True
         Me.txtReply_Date.SetFocus
      Else
    docmd RunSQL  "Update tbl Set ......"
    'and other things I need to happen
    To get to a new record I add this to the After Update event.

    Code:
    DoCmd.GoToRecord , Me.Name, acNewRec
    Unless somebody says otherwise, I think I'm good. My only objection at this point is I would like to avoid the msgbox if the user clicks save. As it is, he clicks Save Record, then the message box asks the same question. It's one of those annoyances I can live with, but I'd like to avoid.
    Last edited by paxham; 10-14-11 at 14:00. Reason: posting an addendum

  12. #12
    Join Date
    Aug 2011
    Location
    Richmond, VA
    Posts
    38
    Follow up! I just realized I don't need the message box at all. As long as all my code runs in the before update event I don't care if they click the Save button or just flip through the fields.

    Thank you for pointing me in the right direction. Consider this one solved.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •