
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