PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
Work around for VB6's OpenCurrentDatabase command-VBForums
Results 1 to 11 of 11

Thread: Work around for VB6's OpenCurrentDatabase command

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2004
    Posts
    541

    Work around for VB6's OpenCurrentDatabase command

    Hello, all,

    The following function will open and control an instance of a password protected Access database from VB6.
    VB Code:
    1. expression.OpenCurrentDatabase(filepath, Exclusive, bstrPassword)

    Unfortunately, this cannot be used until Access XP or greater. Just wondering if maybe someone found some workaround for this (maybe pass a password via shell or something). Your help would be greatly appreciated.

    Strick

  2. #2
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,692

    Re: Work around for VB6's OpenCurrentDatabase command

    As someone else here is wont to say, "use ado".

  3. #3
    Frenzied Member d3gerald's Avatar
    Join Date
    Jan 2006
    Posts
    1,348

    Re: Work around for VB6's OpenCurrentDatabase command

    Quote Originally Posted by stricknyn
    Hello, all,

    The following function will open and control an instance of a password protected Access database from VB6.
    VB Code:
    1. expression.OpenCurrentDatabase(filepath, Exclusive, bstrPassword)

    Unfortunately, this cannot be used until Access XP or greater. Just wondering if maybe someone found some workaround for this (maybe pass a password via shell or something). Your help would be greatly appreciated.

    Strick
    could you make it clear what you want to do?
    On error goto Trap

    Trap:
    in case of emergency, drop the case...

    ****************************************
    If this post has been resolved. Please mark it as "Resolved" by going through the "Thread Tools" above and clicking on the "Mark Thread Resolved " option.
    if a post is helpful to you, Please Rate it by clicking on the Rate link right below the avatar

  4. #4
    Frenzied Member pnish's Avatar
    Join Date
    Aug 2002
    Location
    Tassie, Oz
    Posts
    1,916

    Re: Work around for VB6's OpenCurrentDatabase command

    Is this VBA? ie are you doing this from within Access?
    Pete

    No trees were harmed in the making of this post, however a large number of electrons were greatly inconvenienced.

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

    Re: Work around for VB6's OpenCurrentDatabase command

    OpenCurrentDatabase is for Access (or Access automation) rather than VB6.

    You can use ADO to connect to an Access database from VB6, see the "ADO Tutorial" link below for an example and explanation.

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2004
    Posts
    541

    Re: Work around for VB6's OpenCurrentDatabase command

    Hello, all,

    I want to open an instance of Access from VB6 and control it. I do not want to connect to the DB (ADO) which is different from controlling it. I don't have any problems doing this in VB6 when there's no password. I found that the OpenCurrentDatabase command has an added password parameter that with Access XP and greater. I was just trying to see if someone has a work around for this for versions 2000 and older.

    Thanks,

    Strick

  7. #7
    Super Moderator RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,698

    Re: Work around for VB6's OpenCurrentDatabase command

    Add a reference to MS Access xx.0 Object Library and then you need to create an application object variable of Access.Application type in order to execute that method - OpenCurrentDatabase.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  8. #8

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2004
    Posts
    541

    Re: Work around for VB6's OpenCurrentDatabase command

    Hello, all,

    Found a work around after scouring the net for a way to open an instance of MS Access (Pre Access XP) from VB6. The sample I found works great. I can open an instance of a password protected access db in Access 97 and 2000. Only bad thing is that the sample I found is for DAO. Just wondering if anyone could translate this DAO sample to the ADO equivalent?

    VB Code:
    1. Sub OpenPasswordProtectedDB()
    2.  
    3.    Dim acc As Access.Application
    4.    Dim db As DAO.Database
    5.    Dim strDbName As String
    6.     strDbName = "J:\test.mdb"
    7.    Set acc = New Access.Application
    8.    acc.Visible = True
    9.    Set db = acc.DBEngine.OpenDatabase(strDbName, False, False, ";PWD=test")
    10.    acc.OpenCurrentDatabase strDbName
    11.    db.Close
    12.    Set db = Nothing
    13. End Sub


    Thanks in advance,

    Strick

  9. #9
    New Member
    Join Date
    Sep 2008
    Posts
    1

    Re: Work around for VB6's OpenCurrentDatabase command

    Dim app As New Application
    Dim cnn As New ADODB.Connection

    Set cnn = New ADODB.Connection
    cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\abc\abc.mdb;Mode=Share Deny None;" & _
    "Jet OLEDB:System database=workgroup_name.mdw", user_id, password

    app.OpenCurrentDatabase ("c:\abc\abc.mdb")
    app.CloseCurrentDatabase
    cnn.Close

    Set cnn = Nothing
    Set app = Nothing

  10. #10
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,692

    Re: Work around for VB6's OpenCurrentDatabase command

    Quote Originally Posted by mcourter
    Dim app As New Application
    Dim cnn As New ADODB.Connection

    Set cnn = New ADODB.Connection
    Bad idea - if you Dim ... As New, you can't Set = Nothing.

    Dim

    Then Set = New
    The most difficult part of developing a program is understanding the problem.
    The second most difficult part is deciding how you're going to solve the problem.
    Actually writing the program (translating your solution into some computer language) is the easiest part.

    Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.

    Please Help Us To Save Ana

  11. #11
    Head Hunted anhn's Avatar
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    3,669

    Re: Work around for VB6's OpenCurrentDatabase command

    Although many Microsoft's examples use: Dim Something As New SomeObject
    Code:
    Sub DoNotDimAsNew()
        Dim Coll1 As New Collection
        
        Set Coll1 = Nothing
        If Coll1 Is Nothing Then
            Debug.Print "Coll1 is Nothing"
        Else
            Debug.Print "Coll1 is NOT Nothing"
        End If
        
        
        Dim Coll2 As Collection
        Set Coll2 = New Collection
        
        Set Coll2 = Nothing
        If Coll2 Is Nothing Then
            Debug.Print "Coll2 is Nothing"
        Else
            Debug.Print "Coll2 is NOT Nothing"
        End If
    End Sub
    Code:
    Coll1 is NOT Nothing
    Coll2 is Nothing
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • If your question was answered please use Thread Tools to mark your thread [RESOLVED]
    • Don't forget to RATE helpful posts

    • Baby Steps a guided tour
    • IsDigits() and IsNumber() functions • Wichmann-Hill Random() function • >> and << functions for VB • CopyFileByChunk

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