Results 1 to 7 of 7
  1. #1
    mavisyew is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Aug 2014
    Posts
    34

    Save the record before runing the report

    Hi All,

    I have created a database for case incident.
    When the user create a case, and the Status = "new" and Priority = "Critical" Then when i click on the Save button, it suppose to save the record then send out the report.

    Below is my code.
    Private Sub Form_BeforeUpdate(Cancel As Integer)
    Dim strResponse As String
    If Me.Dirty Then
    Select Case MsgBox( _
    Prompt:="This record has been changed" & _
    vbCrLf & "Do you want to save?", _
    Buttons:=vbExclamation Or vbYesNo)
    Case vbYes
    DoCmd.RunCommand acCmdSave

    If Me.Priority = "Critical" And Me.Status = "New" Then
    DoCmd.SendObject acSendReport, "ReportCriticalCase", acFormatPDF, "123@yahoo.com", 123@yahoo.com, , "Critical Case", "Critical Case", False
    End If

    Case vbNo
    DoCmd.RunCommand acCmdUndo
    End Select
    End If
    End Sub

    Now the problem is that it will send out the report before it save the data and my report sent out is empty.



    Anyone can advice what happen to my code?

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Try: acCmdSaveRecord
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    The following code is in the middle of your MsgBox code. Perhaps it should be somewhere else. Also, It seems like the criteria is looking for a record that has not been saved yet.

    If Me.Priority = "Critical" And Me.Status = "New" Then
    DoCmd.SendObject acSendReport, "ReportCriticalCase", acFormatPDF, "123@yahoo.com", 123@yahoo.com, , "Critical Case", "Critical Case", False
    End If

  4. #4
    mavisyew is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Aug 2014
    Posts
    34
    Hi June7,

    I changed the code to 'DoCmd.RunCommand acCmdSaveRecord' but it prompt me a macro error message.


    Hi ItsMe,

    I want the system to auto send out the report when i save the record.
    Where do you suggest to put the code?

  5. #5
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Regarding the constant, acCmdSaveRecord, June is correct. If you are getting an error on that line, it may be because you do not have focus on the form object. So maybe
    Me.SomeControlName.SetFocus
    DoCmd.RunCommand acCmdSaveRecord

    or use
    Me.Dirty = False

    However, I just realized you are using the BeforeUpdate event. This may be causing the error by itself. The form is already in the process of updating itself so no need to call the save.

    I would start by commenting out the code to send the report and concentrate on saving/committing the record to the table first. You have a couple of issues here and are trying to accomplish too much in one block of code. Split it up.

    Maybe something like this for your BeforeUpdate event handler would be more appropriate.
    Code:
    Dim intResponse As Integer
    intResponse = MsgBox("Do you want to save the changes made to this record?", vbYesNo + vbDefaultButton2 + vbQuestion, "Save Changes")
    
        If intResponse = vbNo Then
            Cancel = True
        End If

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Good point about the BeforeUpdate event already in process of saving record. I did not notice.

    Perhaps the code to send report should be in AfterUpdate.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    mavisyew is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Aug 2014
    Posts
    34
    Hi Both,

    Thanks!
    Think i got it.

    I have move the send report to AfterUpdate and is working.

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

Similar Threads

  1. Replies: 28
    Last Post: 05-25-2014, 04:01 PM
  2. Replies: 5
    Last Post: 04-20-2013, 11:32 AM
  3. Replies: 3
    Last Post: 10-08-2012, 08:40 AM
  4. Replies: 8
    Last Post: 09-27-2012, 11:12 AM
  5. Runing a report from combobox
    By frksdf in forum Programming
    Replies: 2
    Last Post: 09-13-2011, 09:01 PM

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