Results 1 to 4 of 4
  1. #1
    Bronze Lounger
    Join Date
    Feb 2001
    Location
    Escondido, California, USA
    Posts
    1,458
    Thanks
    0
    Thanked 1 Time in 1 Post

    Printing from new record (2003 / 2000)

    I can print a report from a data entry form as long as the record i'm working on has been saved. However, when entering a new record, but before exiting (i.e. saving) it, it doesn't print the new record, but reverts back to the first record in the db. I assume that's because the record hasn't yet been saved. Below is the code for printing, but it seems to me I need some additional code to save the record before printing it. Any suggestions?


    Private Sub cmdPrint_Click()
    On Error GoTo Err_cmdPrint_Click
    Dim stDocName As String

    stDocName = "rptOrderTrack"

    If Me.Dirty Then
    DoCmd.Requery
    End If

    DoCmd.OpenReport stDocName, acNormal, _
    WhereCondition:="[Order#]=" & Me.[Order#]

    Exit_cmdPrint_Click:
    Exit Sub

    Err_cmdPrint_Click:
    MsgBox Err.Description
    Resume Exit_cmdPrint_Click

    End Sub

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Printing from new record (2003 / 2000)

    Instead of

    DoCmd.Requery

    use

    RunCommand acCmdSaveRecord

  3. #3
    Bronze Lounger
    Join Date
    Feb 2001
    Location
    Escondido, California, USA
    Posts
    1,458
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Printing from new record (2003 / 2000)

    Thanks again. I knew there had to be a way. I wish VBA wasn't so inconsistent. DoCmdRequery is very straightforward so one would normally expect to save a record with something like DoCmdSaveRecord or similar. Instead the "RunCommand ...." syntax is totally different. I'll never understand why.

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Printing from new record (2003 / 2000)

    There are historical reasons for this. The DoCmd methods are the equivalent of macro actions, and the RunCommand method provides the equivalent of menu options.

    I suppose that if the Access team could redesign the object model from scratch, they would come up with a more logical and consistent structure, but with the large number of existing Access applications, it is impossible to change it now.

Posting Permissions

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