troubleshooting Question

Receiving RunTime Error 3001 (Invalid Argument) When Running CreateDatabase method

Avatar of meridythe
meridythe asked on
Microsoft Access
5 Comments1 Solution2277 ViewsLast Modified:
I am receiving the runtime error 3001 (Invalid argument) when running the following code.  The error comes up whe the code hits the "Set dbsNew = wrkDefault.CreateDatabase(strDirectory & strDB & ".mdb", dbLangGeneral, dbEncrypt)" line of code.  I have the Microsoft DAO 3.6 Object Library.
Function CreateDatafile()
On Error GoTo ErrorHandler

Dim wrkDefault As DAO.Workspace, dbs As DAO.Database
Dim dbsNew As DAO.Database, strSQL As String, tdf As DAO.TableDef
Dim tdfNew As DAO.TableDef, fld As DAO.Field, flds As DAO.Fields
Dim fldOld As DAO.Field, fldName As String, counter As Integer
Dim strDB As String, rstServer As DAO.Recordset
Dim rst As DAO.Recordset, rstNew As DAO.Recordset
Dim strDirectory As String, IsFileDIR As Boolean, strTableName As String
Dim strPath As String

    Set dbs = CurrentDb()
    ' Get default Workspace.
    Set wrkDefault = DBEngine.Workspaces(0)
    Set dbs = CurrentDb()
    Set rst = dbs.OpenRecordset("tblDataTables")        'Recordset has the tables you wish to copy into new database

    strDB = "Attorney Reporting"
    strDirectory = "C:\My Data\Databases\Attorney Reporting\Copy\"       'Target where you want new database to be created
    MkDir strDirectory
    strPath = strDirectory & strDB & ".mdb"
    If fIsFileDIR(strPath) Then _
    Kill strPath

    ' Create a new encrypted database with the specified collating order.
    Set dbsNew = wrkDefault.CreateDatabase(strDirectory & strDB & ".mdb", _
        dbLangGeneral, dbEncrypt)

    While Not rst.EOF
        strTableName = rst!TableName
        Set tdf = dbs.TableDefs(rst!TableName)
        Set flds = tdf.Fields

        With dbsNew
            Set tdfNew = dbsNew.CreateTableDef(strTableName)
            For counter = 0 To flds.Count - 1
                fldName = flds(counter).Name
                Set fld = tdf.CreateField(flds(counter).Name, flds(counter).Type)
                Set fldOld = tdf.Fields(fldName)
                tdfNew.Fields.Append fld
                fld.DefaultValue = fldOld.DefaultValue
                fld.Size = fldOld.Size
                fld.AllowZeroLength = fldOld.AllowZeroLength
                fld.Required = fldOld.Required
                fld.Properties(1) = fldOld.Properties(1)
            Next counter
            dbsNew.TableDefs.Append tdfNew
        End With
        'Transfer the data to new table
        DoCmd.TransferDatabase acExport, "Microsoft Access", strPath, acTable, _
            rst!TableName, rst!TableName, False



    Exit Function
    If Err.Number = 75 Then
        Resume Next
        MsgBox Err.Number & Err.Description
        Resume ExitHere
    End If
End Function
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 5 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros