Problem creating mdb file using ADOX


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: Problem creating mdb file using ADOX

  1. #1
    Earl Guest

    Problem creating mdb file using ADOX


    I'm trying to create an empty Access 2000 mdb file based on the system date
    - The date when the procedure was invoked in ddmmyyyy format. April 16, 2002
    would create an access file of: 02162002.mdb. Here's my code:

    Private Sub Create_db_Click()
    Dim db_date As String
    Dim db_date_check As Integer
    Dim db_name As String

    Dim xoTable As ADOX.Catalog
    Set xoTable = New ADOX.Catalog

    Dim sCnn As String


    db_date = Format$(Now, "mmddyyyy")
    db_path = "c:\bin\"
    db_name = db_date & db_path & ".mdb"


    sCnn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=db_name;Jet OLEDB:Engine
    Type=5;"

    xoTable.Create sCnn

    End Sub

    When this code is executed, I receive the following error: "run-time error
    -2147217897 (80040e17) Database already exists" This error is generated even
    when the file truly doesn't exist. This code works fine if I directly substitute
    db_name of Data Source= with the statement: source=c:\bin\0162002.mdb. But
    this would defeat my purpose of wanting to pass date variable to the source
    string.

    Thanks in advance for your help.
    earl





  2. #2
    Michael Culley Guest

    Re: Problem creating mdb file using ADOX

    > db_name = db_date & db_path & ".mdb"

    date and path are back to front

    --
    Michael Culley
    www.vbdotcom.com



  3. #3
    Rick Guest

    Re: Problem creating mdb file using ADOX




    Is this really the path to the file?

    db_name = db_date & db_path & ".mdb"

    or is

    db_name = db_path & db_date & ".mdb"

    Have a good day!
    Rick




    "Earl" <earl@mail.com> wrote:
    >
    >I'm trying to create an empty Access 2000 mdb file based on the system date
    >- The date when the procedure was invoked in ddmmyyyy format. April 16,

    2002
    >would create an access file of: 02162002.mdb. Here's my code:
    >
    >Private Sub Create_db_Click()
    >Dim db_date As String
    >Dim db_date_check As Integer
    >Dim db_name As String
    >
    >Dim xoTable As ADOX.Catalog
    >Set xoTable = New ADOX.Catalog
    >
    >Dim sCnn As String
    >
    >
    >db_date = Format$(Now, "mmddyyyy")
    >db_path = "c:\bin\"
    >db_name = db_date & db_path & ".mdb"
    >
    >
    >sCnn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=db_name;Jet OLEDB:Engine
    >Type=5;"
    >
    >xoTable.Create sCnn
    >
    >End Sub
    >
    >When this code is executed, I receive the following error: "run-time error
    >-2147217897 (80040e17) Database already exists" This error is generated

    even
    >when the file truly doesn't exist. This code works fine if I directly substitute
    >db_name of Data Source= with the statement: source=c:\bin\0162002.mdb. But
    >this would defeat my purpose of wanting to pass date variable to the source
    >string.
    >
    >Thanks in advance for your help.
    >earl
    >
    >
    >
    >



  4. #4
    Earl Guest

    Re: Problem creating mdb file using ADOX


    Thanks for the reponses Michael & Rick,

    I discovered the path order error (my cut & paste error) after posting the
    message. But thank you for pointing it out. I regards to the error message
    I was experiencing even after correcting the path sequence, I discovered
    that the problem was caused from having nested the string variabe db_name
    within the data source connection string. Modifying the string from: sCnn
    = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=db_name;Jet OLEDB:Engine
    Type=5;"
    To: "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & db_name&";Jet OLEDB:Engine
    Type=5;" resolved the error messages.

    Thank you everyone for your prompt feedback and assistance.



    "Earl" <earl@mail.com> wrote:
    >
    >I'm trying to create an empty Access 2000 mdb file based on the system date
    >- The date when the procedure was invoked in ddmmyyyy format. April 16,

    2002
    >would create an access file of: 02162002.mdb. Here's my code:
    >
    >Private Sub Create_db_Click()
    >Dim db_date As String
    >Dim db_date_check As Integer
    >Dim db_name As String
    >
    >Dim xoTable As ADOX.Catalog
    >Set xoTable = New ADOX.Catalog
    >
    >Dim sCnn As String
    >
    >
    >db_date = Format$(Now, "mmddyyyy")
    >db_path = "c:\bin\"
    >db_name = db_date & db_path & ".mdb"
    >
    >
    >sCnn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=db_name;Jet OLEDB:Engine
    >Type=5;"
    >
    >xoTable.Create sCnn
    >
    >End Sub
    >
    >When this code is executed, I receive the following error: "run-time error
    >-2147217897 (80040e17) Database already exists" This error is generated

    even
    >when the file truly doesn't exist. This code works fine if I directly substitute
    >db_name of Data Source= with the statement: source=c:\bin\0162002.mdb. But
    >this would defeat my purpose of wanting to pass date variable to the source
    >string.
    >
    >Thanks in advance for your help.
    >earl
    >
    >
    >
    >



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center