Results 1 to 11 of 11
  1. #1
    data808 is offline Noob
    Windows XP Access 2010 32bit
    Join Date
    Aug 2012
    Posts
    727

    Print / Save Button

    Have a form that the user will print after filling in some fields. On the form I have 4 buttons. 2 buttons are for opening different forms. 1 is to close the whole database. The last one is to print the form. I have the form set so that when the user opens the this particular form, it is blank and ready for the new record to be entered. In other words the navigation options are gone to scroll through previous records. All the user sees a blank form that needs to be filled out. Once the user fills out the fields and then prints the form, the record is saved into the table and the form becomes blank again for another new record to be entered.

    The problem I am having now is that if the user cancels the print from the print window, the record will still be saved. Also if the user clicks on any of the other 3 buttons, whether it be to open another different form or close the database, it will also save the record into the table.

    How do I prevent this from happening? I would ONLY like the record to be saved into the table IF they successfully print the form. So this I think would need to be tied to the print button but the other 3 buttons would need something to prevent the form from saving the record if any of the other buttons are clicked. I should also mention I setup the buttons with macros. I don't know anything about VBA.



    Can anyone help with this?

  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    It seems as though you will need to validate saving the record in a separate process from printing. Perhaps printing a report will afford you the opportunity to separate printing from data entry. Another approach may be to have a second (copy) form open and do the printing. You could have the form open to the specific record and maybe open in hidden mode.

    You may have to change the work flow in order to do this. Business rules can be fun...

  3. #3
    data808 is offline Noob
    Windows XP Access 2010 32bit
    Join Date
    Aug 2012
    Posts
    727
    No I need it to vanish when they print so the user does not change the record once its printed. This way I know exactly what they are printing without them altering the record after. What else ideas do you have for this? Remember the user is only able to see the one record they are working on. Once they print, the form goes blank and ready for the next record. They cannot look at previous records in the form or table. I'm going to hide the table. Let me know if there is a way to do what I need.
    Last edited by data808; 02-19-2014 at 03:04 PM.

  4. #4
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    I should also mention I setup the buttons with macros. I don't know anything about VBA.
    I think your requirements can be met, but it requires VBA code. I do not use macros because they are too limiting - I only use VBA code.


    It sounds like you are using bound forms; data is saved anytime you move to a new record, change forms, print.... automatic saves.
    After data is entered, the form becomes "dirty". To go to a different form, you would have to cancel the save and undo the data entry.


    Or you could use unbound forms.
    The problem with unbound form is that *you* have to do the heavy lifting.
    You write code to manage the data, when/if to save the data, clear the controls... everything. (also requires some SQL knowledge)

    I don't know how to meet your requirements using just macros....
    Last edited by ssanfu; 02-19-2014 at 04:32 PM. Reason: computer cannot spell correctly

  5. #5
    data808 is offline Noob
    Windows XP Access 2010 32bit
    Join Date
    Aug 2012
    Posts
    727
    Yes bound forms is exactly what I am using. What you've described is spot on. So maybe if I mess with the dirty property you think I can get it to do what I need?

    "To go to a different form, you would have to cancel the save and undo the data entry."

    I've actually had this idea but couldn't figure out how to get it done. I do have a VBA that I saved from another database that will ask the user if they want to save or undo before update. So whether its a new record or an edit on an existing record, it will prompt the user to save changes or undo. The problem with this is that if the user prints or goes to another form, it will ask if they want to save and they can easily just click undo and the record won't save even if they print. The macro I have now on the print button has run command-print selection, close form, then reopen the same form. This is why the user will only see a blank form after the print. I am also having trouble with the fact that if they cancel the print it will still go through the macros and save the record even though the record was never printed. The thing is, this document is going to be given to customers and I need to see exactly what they are giving the customer. So that's why I setup the database like this.

  6. #6
    data808 is offline Noob
    Windows XP Access 2010 32bit
    Join Date
    Aug 2012
    Posts
    727
    Ok I got a little closer. On one of the buttons that I use to go to another form, I put the run command-undo macro first, then open new form and close current form. So if the user enters any data in the form and then decides not to print but instead clicks on this button to open a new different form, it will not save the record. HOWEVER, it will not work if the user does not enter anything in this form because there is nothing to undo. Any ideas to get around that?

  7. #7
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    HOWEVER, it will not work if the user does not enter anything in this form because there is nothing to undo. Any ideas to get around that?
    In VBA, I would check the dirty property.
    TRUE would mean data had been entered,
    FALSE would mean there were no entries.

    If me.Dirty then
    Me.Undo
    End if

    Don't know how to do this in a macro...

  8. #8
    data808 is offline Noob
    Windows XP Access 2010 32bit
    Join Date
    Aug 2012
    Posts
    727
    I have no problem converting the macros to VBA code using the feature in Access. Would you be able to assist me in the VBA code I need to get this done? This would be a life saver. I'm getting close to the deadline on this project and I'm suffering on the areas I know would be so much easier if I knew how to do VBA. Thanks so much for the help.

  9. #9
    data808 is offline Noob
    Windows XP Access 2010 32bit
    Join Date
    Aug 2012
    Posts
    727
    Oh and there is no dirty property for the command button. Only for the form itself in the event tab. Unless, can you create an event property for the button?

  10. #10
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    I might have time on Sun to look at your dB....
    Do a compact & Repair, Zip it, and attach it to a post. Tell me which form to look at.

    ...there is no dirty property for the command button
    Correct. When you type the first character in a control on a form, the form becomes "Dirty".

  11. #11
    data808 is offline Noob
    Windows XP Access 2010 32bit
    Join Date
    Aug 2012
    Posts
    727
    I figured it out with some help from looking online and thinking of some of it myself. I was pretty proud of myself for doing a lot of the thought process to finish this. I will post the code below to show you what I did. I just want to say thank you so much for replying and helping me out too. If it wasn't for forums like this, it would take a lot longer to get anywhere with Access. Thanks again and here is the code for the 4 buttons:

    Private Sub Close_Form_Click()

    If Me.NewRecord And Me.Dirty Then
    Me.Undo
    End If

    DoCmd.Quit

    End Sub

    Private Sub cmdMenu_Click()

    If Me.NewRecord And Me.Dirty Then
    Me.Undo
    End If

    DoCmd.OpenForm "Main Menu", acNormal
    DoCmd.Close acForm, "DL Clearance"

    End Sub


    Private Sub cmdQuery_Click()

    If Me.NewRecord And Me.Dirty Then
    Me.Undo
    End If

    DoCmd.OpenForm "Query Menu", acNormal
    DoCmd.Close acForm, "DL Clearance"

    End Sub

    Private Sub cmdSavePrint_Click()

    If Not IsNull(Me.Clerk_Initial) Then
    DoCmd.Save
    DoCmd.GoToRecord , , acNewRec
    MsgBox "Record has been saved. To delete record, report to a Supervisor."
    DoCmd.PrintOut
    Else
    DoCmd.CancelEvent
    Beep
    MsgBox "You must enter your initials.", vbInformation, "Required Data"
    DoCmd.GoToControl "[Clerk Initial]"
    End If

    End Sub

    I just realized that the Docmd.CancelEvent for the last button is probably not even necessary. But hey, I'm learning. haha

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

Similar Threads

  1. Replies: 4
    Last Post: 02-12-2014, 12:49 PM
  2. form - save entered data only with save button
    By cbrxxrider in forum Forms
    Replies: 3
    Last Post: 10-20-2013, 12:39 PM
  3. Replies: 3
    Last Post: 10-08-2012, 08:40 AM
  4. Replies: 10
    Last Post: 06-20-2012, 09:50 AM
  5. Replies: 0
    Last Post: 02-22-2011, 05:04 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