Results 1 to 5 of 5
  1. #1
    RMI is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2011
    Posts
    6

    Unhappy Cannot navigate pages in print preview

    I have a function in VBA that:
    1 - creates a temp db
    2 - creates a table in temp db
    3 - copies data from 2 different tables into that temp table
    4 - links the temp table into the currentdb
    5 - opens a report on that table (and others) in print preview
    6 - loops until the report is closed
    7 - removes the link
    8 - closes the other db
    9 - deletes the other db


    exits

    Now, when I have the report in print preview, I cannot use the page navigation buttons at the bottom to change pages. I can use CTRL-P to print it (usually to a PDF) so that I know it is formatted correctly.

    I am confused and a Google search didn't seem to come up with anything I could use.

    Thanks for any help!
    RMI

  2. #2
    hertfordkc is offline 18 year novice
    Windows XP Access 2007
    Join Date
    Mar 2011
    Posts
    481

    You actually have a loop in your VBA function?

    Quote Originally Posted by RMI View Post
    I have a function in VBA that:

    4 - links the temp table into the currentdb
    5 - opens a report on that table (and others) in print preview
    6 - loops until the report is closed
    7 - removes the link
    exits

    Now, when I have the report in print preview, I cannot use the page navigation buttons at the bottom to change pages. I can use CTRL-P to print it (usually to a PDF) so that I know it is formatted correctly.
    RMI
    Why not exit the function and have a VBA onclose function in the report that cleans everything up?
    Just a guess.

  3. #3
    RMI is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2011
    Posts
    6
    Quote Originally Posted by hertfordkc View Post
    Why not exit the function and have a VBA onclose function in the report that cleans everything up?
    Just a guess.
    I will rework the process and let you know how it goes.

    Thanks for pointing out the obvious...

    Edit:
    Code:
    Option Compare Database
    Option Explicit
    Dim oDB As DAO.Database
    Dim sTable As String
     
    Private Sub Report_Open(Cancel As Integer)
        Dim sFN As String
        Dim tdfTable As TableDef
     
        ' Set Variables
        sTable = "ContactLog"
     
        ' Create a temp database
        sFN = CurrentProject.Path & "\Temp-" & Format(Now(), "yyyymmddhhNnss") & ".accdb"
        modMain.CreateDatabaseDAO (sFN)
     
        ' Open the database
        Set oDB = OpenDatabase(sFN)
     
        ' Create the table
        oDB.Execute "CREATE TABLE " & sTable _
            & " (lname CHAR, fname CHAR, cdate DATETIME, ctype CHAR, reason MEMO, outcome MEMO);"
     
        ' Link the table to this database
        Set tdfTable = CurrentDb.CreateTableDef(sTable)
        tdfTable.Connect = ";Database=" & sFN
        tdfTable.SourceTableName = "ContactLog"
        CurrentDb.TableDefs.Append tdfTable
        Set tdfTable = Nothing
     
        ' Insert data from contacts
        CurrentDb.Execute "INSERT INTO " & sTable & " ( lname, fname, cdate, ctype, reason, outcome ) SELECT tblContacts.lname, tblContacts.fname, tblContacts.cdate, tblContacts.ctype, tblContacts.reason, tblContacts.outcome FROM tblContacts INNER JOIN tblStudents ON (tblContacts.fname = tblStudents.fname) AND (tblContacts.lname = tblStudents.lname) WHERE tblStudents.Active = True"
     
        ' Insert data from weekly reports
        CurrentDb.Execute "INSERT INTO " & sTable & " ( lname, fname, cdate, ctype, reason ) SELECT tblDaily.lname, tblDaily.fname, tblDaily.tdate AS cdate, 'W' AS ctype, tblDaily.comments AS reason FROM tblDaily WHERE tblDaily.comments Is Not Null"
     
        ' Close the temp database
        Set oDB = Nothing
    End Sub
     
    Private Sub Report_Close()
        ' Remove the link to the temp table
        CurrentDb.TableDefs.Delete sTable
     
        ' delete the database
        Kill CurrentProject.Path & "\Temp-*.accdb"
    End Sub
    So, everything worked fine until it tried to delete the temp db...

    Apparently there is a link to the temp db that set odb=nothing and clearing the table link doesn't fix.

    I am lost. What am I missing.

    Thanks for your help so far!!!
    Last edited by RMI; 11-07-2011 at 07:46 PM. Reason: Added what happened...

  4. #4
    RMI is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2011
    Posts
    6
    Can anyone help?

  5. #5
    Join Date
    May 2010
    Posts
    339
    You could try and set your record source to ""

    On a form it might look like this.

    Private Sub Form_Close()
    Dim strSQL As String
    Me.RecordSource = ""
    strSQL = "Drop Table sTable"
    CurrentDb.Execute strSQL, dbfailonerror
    Kill CurrentProject.Path & "\Temp-*.accdb"
    End Sub

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

Similar Threads

  1. print preview
    By rmohebian in forum Access
    Replies: 4
    Last Post: 02-14-2011, 08:10 AM
  2. Multiple Pages Print
    By gmitchell@exbrief.com in forum Forms
    Replies: 1
    Last Post: 01-23-2011, 06:06 PM
  3. Envelope wants to print four pages
    By gafort in forum Forms
    Replies: 6
    Last Post: 01-06-2011, 11:24 PM
  4. Print Preview different from Print Hardcopy
    By peterc in forum Reports
    Replies: 4
    Last Post: 10-27-2009, 05:35 AM
  5. Error when trying to print or print preview
    By TriAdX in forum Reports
    Replies: 8
    Last Post: 08-25-2009, 08:20 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