Results 1 to 5 of 5

Thread: [RESOLVED] report - no report

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2006
    Posts
    13

    Resolved [RESOLVED] report - no report

    Hi,
    I am trying to view an access report in visual basic, i know it can be done but Im having trouble. Please could you have a look at my code and see if anything looks wrong as i get the following error...... "run time error '7866' access can't open the database because it is missing, or open exclusively by another user."

    VB Code:
    1. Dim AcApp As Access.Application
    2. Set AcApp = New Access.Application
    3. Dim strPath As String
    4.  
    5. strPath = App.Path
    6. strPath = strPath & "C:\Documents and Settings\Tim\Desktop\Program\Database\database.mdb"
    7.  
    8. AcApp.OpenCurrentDatabase strPath
    9. AcApp.Visible = True
    10. AcApp.DoCmd.OpenReport "payments", acViewPreview
    11. AcApp.DoCmd.Maximize
    12.  
    13. AcApp.Quit
    14. Set AcApp = Nothing

    When i got the error message I checked the directory names and they are fine. So i then tried to close the database connection with this code before the report coding began...

    VB Code:
    1. cn.close

    and I got this message "object variable or block variable not set"
    If you can help me I will be very grateful.

    I am using vb6 and a access 97 database. I have selected the microsoft access 10.0 object library.

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: report - no report

    I checked the directory names and they are fine.
    Really? With this code:
    VB Code:
    1. strPath = App.Path
    2. strPath = strPath & "C:\Documents and Settings\Tim\Desktop\Program\Database\database.mdb"
    You will get a directory/file name like this:

    C:\test\C:\Documents and Settings\Tim\Desktop\Program\Database\database.mdb

    ..which isn't valid


    If the database is in the same folder as your application, you can use this:
    VB Code:
    1. strPath = App.Path & "database.mdb"
    or if it is a fixed path,use this:
    VB Code:
    1. strPath = "C:\Documents and Settings\Tim\Desktop\Program\Database\database.mdb"

  3. #3

    Thread Starter
    New Member
    Join Date
    Jan 2006
    Posts
    13

    Re: report - no report

    Hey many thanks I never knew me dying my hair would have such a great effect on me lol.
    ummmm..... One final problem when the report appears it immediately dissappears, any ideas why that is? I am using the AcApp.DoCmd.Maximize command aswell

  4. #4
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: report - no report

    Well you have "AcApp.Quit" just after that, which closes the application - and therefore the report too.

    You may want some kind of pause in there, I guess a msgbox or similar.

  5. #5

    Thread Starter
    New Member
    Join Date
    Jan 2006
    Posts
    13

    Re: report - no report

    many thanks. Problem solved.

Posting Permissions

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



Click Here to Expand Forum to Full Width