dcsimg
Results 1 to 15 of 15

Thread: [RESOLVED] How to open *.mdb file(Access 2000 aplication) with VB6 code?

  1. #1

    Thread Starter
    Addicted Member kutlesh's Avatar
    Join Date
    Jun 2018
    Location
    Skopje, Macedonia
    Posts
    189

    Resolved [RESOLVED] How to open *.mdb file(Access 2000 aplication) with VB6 code?

    I have this method which is clicking on an image:

    Code:
    Private Sub Image7_Click()
        Dim ref As Reference
        Dim objaccess As Access.Application
        Dim errorMsg As String
        Dim methodName As String
        methodName = "Image7_Click"
        
        On Error GoTo appError
        StatusBar1.Panels(1).Text = ""
        
        Set objaccess = CreateObject("Access.Application")
        ' fails with error: Microsoft Access can't open the database because it is missing, or opened exclusively by another user., 7866, -1, MSAccess
        objaccess.OpenCurrentDatabase "MyDB.mdb"
        
        ' fails with error: You made an illegal function call., 7952, -1, MSAccess
        'For Each ref In objaccess.References
             'Debug.Print ref.FullPath
        'Next
        'objaccess.CloseCurrentDatabase
    
        objaccess.DoCmd.Maximize
        
        Exit Sub
    appError:
        errorMsg = methodName & "(): " & Err.Description & ", " & CStr(Err.Number) & ", " & Err.HelpContext & ", " & Err.Source
        Debug.Print errorMsg
        StatusBar1.Panels(1).Text = errorMsg
    End Sub
    I am using MyDB.mdb in my ADODC components. Could this be the cause this method fails with error message:

    Code:
    Image7_Click(): Microsoft Access can't open the database because it is missing, or opened exclusively by another user., 7866, -1, MSAccess
    If I uncomment the code for printing references to MyDB.mdb, it fails with error:

    Code:
    Image7_Click(): You made an illegal function call., 7952, -1, MSAccess
    I also tired copying MyDB.mdb with other name and then using that other mdb which is not used by my ADODC components. I get still the same two errors I mentioned even with another mdb file.

    What do i do wrong?

  2. #2
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    3,693

    Re: How to open *.mdb file(Access 2000 aplication) with VB6 code?

    Do you want to automate MS-Access, or do you want to access a MDB?

  3. #3

    Thread Starter
    Addicted Member kutlesh's Avatar
    Join Date
    Jun 2018
    Location
    Skopje, Macedonia
    Posts
    189

    Re: How to open *.mdb file(Access 2000 aplication) with VB6 code?

    Hmm, open the mdb and enable other users edit data in tables.

    Also I might want run a macro.

    Is there mixing the the approaches in the given code?

  4. #4
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    3,693

    Re: How to open *.mdb file(Access 2000 aplication) with VB6 code?

    To access/edit data you can use ADO.
    http://www.vbforums.com/showthread.p...ed-May-13-2011

    What would be the need of executing embedded macros?

  5. #5
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    13,031

    Re: How to open *.mdb file(Access 2000 aplication) with VB6 code?

    The one thing that jumps out at me is that you are not providing a path to the mdb, could be looking in the wrong place for it.

  6. #6

    Thread Starter
    Addicted Member kutlesh's Avatar
    Join Date
    Jun 2018
    Location
    Skopje, Macedonia
    Posts
    189

    Re: How to open *.mdb file(Access 2000 aplication) with VB6 code?

    Hmm, the mdb is in the same folder where the form is(Form with Image7 object).

  7. #7
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    7,281

    Re: How to open *.mdb file(Access 2000 aplication) with VB6 code?

    ONE way:

    Code:
    Dim cn As ADODB.Connection  'this is the connection object
        Dim rs As ADODB.Recordset   'this is the recordset object
        Dim cmd As ADODB.Command
        Set cmd = New ADODB.Command
        Set cn = New ADODB.Connection
        cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
                              "Data Source=" & App.Path & "\generico.mdb"
        cn.Open
        Set cmd.ActiveConnection = cn
        cmd.CommandType = adCmdText
        cmd.CommandText = "select L, count(L) as myCount from abi_bper where s=? group by L"
        cmd.Parameters.Append cmd.CreateParameter("param1", adVarChar, adParamInput, 1, "0") 'OR, "0" could be a textbox value, etc
        Set rs = cmd.Execute
        
        Do While Not rs.EOF
            'do whatever you want with each or any record returned
            rs.MoveNext
        Loop

  8. #8
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    13,031

    Re: How to open *.mdb file(Access 2000 aplication) with VB6 code?

    Quote Originally Posted by kutlesh View Post
    Hmm, open the mdb and enable other users edit data in tables.

    Also I might want run a macro.

    Is there mixing the the approaches in the given code?
    Rather than opening an mdb which would be done via ADO with no need for any references to Access that you are trying to automate Access and have it open the mdb.

    Your error message seems pretty clear either the mdb is already opened for exclusive access or it is not at the location the program is looking.
    Make sure there are no copies of access running that may have the db locked, make sure that the db is where the program is looking for it.

  9. #9

    Thread Starter
    Addicted Member kutlesh's Avatar
    Join Date
    Jun 2018
    Location
    Skopje, Macedonia
    Posts
    189

    Re: How to open *.mdb file(Access 2000 aplication) with VB6 code?

    No I am not talking to use RecordSet in order to open table in Access, I am saying that the Access 2000 software itself should open and load the mdb file, so other users can browse data in several tables, and edit them as needed.
    Yes, I know I can for example, add another window with DataGrid which will mimic the table in Access 2000, but why bother?

    By the way I need to easily export data from Access tables into Excel for further viewing and data checking.
    The easiest way is to open Access 2000 itself, because the time is short and its just CTRL+A on Access table and copy-paste to Excel worksheet.

  10. #10
    PowerPoster
    Join Date
    Dec 2004
    Posts
    24,717

    Re: How to open *.mdb file(Access 2000 aplication) with VB6 code?

    did you actually try the above suggestion of providing the full path to the .mdb file?
    being in the same folder may not be enough for access to find it
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  11. #11
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    13,031

    Re: How to open *.mdb file(Access 2000 aplication) with VB6 code?

    Quote Originally Posted by kutlesh View Post
    No I am not talking to use RecordSet in order to open table in Access, I am saying that the Access 2000 software itself should open and load the mdb file, so other users can browse data in several tables, and edit them as needed.
    Yes, I know I can for example, add another window with DataGrid which will mimic the table in Access 2000, but why bother?

    By the way I need to easily export data from Access tables into Excel for further viewing and data checking.
    The easiest way is to open Access 2000 itself, because the time is short and its just CTRL+A on Access table and copy-paste to Excel worksheet.
    Well for one thing using ADO does not require the user to have Access installed on their system. Your method requires that they have Access 2000 installed which most users will not have that version if they have Office installed it is likely going to be a much newer version. In order to get your program to work with other versions it would need to be changed to use late binding.

    Of course that has little to do with your issue and you have not said if you checked either of the things I mentioned before so not much more to suggest at this point.

  12. #12
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    2,092

    Re: How to open *.mdb file(Access 2000 aplication) with VB6 code?

    Quote Originally Posted by kutlesh View Post
    No I am not talking to use RecordSet in order to open table in Access, I am saying that the Access 2000 software itself should open and load the mdb file, so other users can browse data in several tables, and edit them as needed.
    Uhmm? ShellExecute?
    One System to rule them all, One IDE to find them,
    One Code to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    For health reasons i try to avoid reading unformatted Code

  13. #13

    Thread Starter
    Addicted Member kutlesh's Avatar
    Join Date
    Jun 2018
    Location
    Skopje, Macedonia
    Posts
    189

    Re: How to open *.mdb file(Access 2000 aplication) with VB6 code?

    I have seen that ShellExecute used to send keys, something like this:

    Code:
    Public Sub Sendkeys(text As Variant, Optional wait As Boolean = False)
        Dim errorMsg As String
        Dim methodName As String
        Dim WshShell As Object
        
        methodName = "Sendkeys"
        
        On Error GoTo errorPoint
        
        Set WshShell = CreateObject("wscript.shell")
        WshShell.Sendkeys CStr(text), wait
        Set WshShell = Nothing
        
        Exit Sub
    errorPoint:
        errorMsg = methodName & "(): " & Err.Number & ", " & Err.Description
        Debug.Print errorMsg
        
    End Sub
    How can i use it to open Access 2000 mdb database?

  14. #14

    Thread Starter
    Addicted Member kutlesh's Avatar
    Join Date
    Jun 2018
    Location
    Skopje, Macedonia
    Posts
    189

    Re: How to open *.mdb file(Access 2000 aplication) with VB6 code?

    Tried this, and it worked:

    Code:
    Private Sub Image7_Click()
        Dim access2000App As Object
        Dim access2000Path As String
        Dim errorMsg As String
        Dim methodName As String
        methodName = "Image7_Click"
        
        On Error GoTo errorPoint
        StatusBar1.Panels(1).text = ""
        
        access2000Path = "MSACCESS.exe """ & App.Path & "\MyDB.mdb"""
        
        Set access2000App = CreateObject("Wscript.shell")
        access2000App.Run access2000Path 
    
        Exit Sub
    errorPoint:
        errorMsg = methodName & "(): " & Err.Description & ", " & CStr(Err.Number) & ", " & Err.HelpContext & ", " & Err.Source
        Debug.Print errorMsg
        StatusBar1.Panels(1).text = errorMsg
    End Sub
    I had a problem with the quotes. Make sure the path of the actual mdb file is surrounded by quotes when you execute the Run method of Wscript.shell.

  15. #15
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    7,281

    Re: How to open *.mdb file(Access 2000 aplication) with VB6 code?

    If you are satisfied that your issue is resolved, use the THREAD TOOLS menu option on this Forum to "Mark Thread As Resolved". That way, people won't 'waste' time to visit this thread to see if you need more help on it.

    Sammi

    EDIT: And don't forget to 'credit' those who helped you solve your issue(s) by clicking on the small * (star) in the post(s) of those who provided that help

Tags for this Thread

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width