Error on creating new module from addin 
Author Message
 Error on creating new module from addin

I'm trying to create a new module in the current mdb from an Addin mda.  Its
consistancly erroring on the line:

    DoCmd.RunCommand acCmdNewObjectClassModule

this is the error msg:

    Run-time error  '2046'
    The command or action  'NewObjectClassModule'  isnt available now.
    *You may be in a read-only database or an unconverted database from an
earlier version of         Microsoft Access.
    *The type of object the action applies to isn't currently selected or
isn't in the active view.
    Use only those commands and macro actions that are currently available
for this database.

Heres my code:

From the Addin form I run this line:

Set mdl = basDataClass.CreateDataClass

then this function fires up:

Public Function CreateDataClass() As Module
    Dim strCode As String
    Dim mdl As Access.Module
    Dim i As Integer
    Dim strTmpName As String
    If FindMod("Class1") = True Then
        DoCmd.DeleteObject acModule, "Class1"
    End If

    'Make Mod Name
    udtProps.strDataModName = "dm" & MID(udtProps.strTableName, 3)

     ReDim Preserve mastMod(Modules.Count)
     For i = Modules.Count - 1 To 0 Step -1
          Set mdl = Modules(i)
          mastMod(i) = mdl.name
          DoCmd.Close acModule, mastMod(i), acSaveYes
     Next
Maybe this line isnt pointing to the current db window.
    DoCmd.SelectObject acModule, , True
ERROR ON THIS LINE
    DoCmd.RunCommand acCmdNewObjectClassModule
    Set mdl = Modules(Modules.Count - 1)

    mdl.InsertLines 3, "Hope this works"
    strTmpName = mdl.name

    DoCmd.Close acModule, strTmpName, acSaveYes
    DoCmd.SelectObject acModule, strTmpName, True
    DoCmd.Rename udtProps.strDataModName, acModule, strTmpName
    DoCmd.OpenModule udtProps.strDataModName

    'Create new mod
    DoCmd.RunCommand acCmdNewObjectClassModule

    DoCmd.Close acModule, udtProps.strDataModName, acSaveYes

    DoCmd.OpenModule udtProps.strDataModName
    Set mdl = Modules(udtProps.strDataModName)

    strCode = "Private Const pcstrCnn As String = """ & ODBC_Name & """" &
vbNewLine & vbNewLine
    strCode = strCode & "Public Function GetList() As ADODB.Recordset" &
vbNewLine
    strCode = strCode "ya ya ya ...."

    'Insert code into the new module, Save, and Close
    mdl.InsertLines 4, strCode
    DoCmd.Save acModule, udtProps.strDataModName
    DoCmd.Close acModule, udtProps.strDataModName
    Set mdl = Nothing
End Function

Can some one please advise on this?

Thanks.

--
George Padvorac

nwis.net, Inc



Mon, 29 Jan 2001 03:00:00 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. VB5 Addin to create procedures with error handling and comment blocks

2. Programmatically create a new module

3. Create New records with a module

4. Creating new Access 97 database by VB code in Access 2000 module

5. Creating a new instance of Winsock in a Class Module

6. Receive Error (404) Automation Error when creating new mailitem from MS Access

7. Addin write-protecting a module?

8. CLSID or GUID, Addin Designer Module

9. ERROR: MS Access couldn't create storage space for a visual basic module

10. ERROR: MS Access couldn't create storage space for a visual basic module

11. Strange error creating Class Module

12. New timesaver addin of Visual Basic

 

 
Powered by phpBB® Forum Software