By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,098 Members | 1,255 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,098 IT Pros & Developers. It's quick & easy.

Programmatically remove a form from Access 2000

P: n/a
Hi,
I'm currently building an application in Access and as part of this
need to import forms and modules from another database. Some of the
imports will be revisions of existing forms/modules so I need to check
and see they already exist before importing them so I can remove the
old one.
I've figured out how to remove the classes and modules before importing
the revised version but I'm having problems with the forms. I was
hoping to use the AccessObject collection but there doesn't seem to be
a 'remove' function - can anyone shed any light?

Thanks in advance

Dave

(DEV_DB is a link to the development database)
--Code--

Public Function ImportScript(scriptID As Integer) As Boolean
Dim rsComponents As New ADODB.Recordset
Dim o_Conn As New ADODB.Connection
Dim m_Conn_Str As String
Dim strSQL As String

On Error GoTo ImportScript_Err

m_Conn_Str = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = " &
DEV_DB & ";User ID=""admin"";Password="""";"
o_Conn.CursorLocation = adUseClient
o_Conn.ConnectionString = m_Conn_Str
o_Conn.Open

With rsComponents
strSQL = "SELECT tblScript.ScriptName, tblScript.ScriptDesc,
tblScript.AccessLevel, tblScriptComponent.ComponentType,
tblScriptComponent.ComponentName, tblScriptComponent.EditDate " & _
"FROM tblScript INNER JOIN tblScriptComponent ON
tblScript.ScriptID = tblScriptComponent.ScriptID WHERE
tblScript.ScriptID = " & scriptID & ";"

..Open strSQL, o_Conn, adOpenForwardOnly, adLockOptimistic
While Not rsComponents.EOF
If .Fields(3) = "adForm" Then
If Not (CheckForExisting(.Fields(3), .Fields(4))) Then
ImportAccessForm (.Fields(4))
End If
ElseIf .Fields(3) = "adModule" Then
If Not (CheckForExisting(.Fields(3), .Fields(4))) Then
ImportModule (.Fields(4))
End If
End If
..MoveNext
Wend
..MoveFirst
strSQL = "INSERT INTO tblInstalledScripts (scriptName,
scriptDesc, accessLevel, ModifiedDate) VALUES " & _
"(""" & .Fields(0) & """,""" & .Fields(1) &
"""," & .Fields(2) & ",#" & .Fields(5) & "#);"
CurrentDb().Execute strSQL
End With
ImportScript_Exit:
ImportScript = True
Exit Function

ImportScript_Err:
ImportScript = False
Exit Function
Resume
End Function

Private Sub ImportAccessForm(sFrmName As String)
' Imports an access form from the development database
DoCmd.TransferDatabase acImport, "Microsoft Access", DEV_DB,
acForm, sFrmName, sFrmName
End Sub

Private Sub ImportModule(sModName As String)
' Imports standard and class modules from the development database
DoCmd.TransferDatabase acImport, "Microsoft Access", DEV_DB,
acModule, sModName, sModName
End Sub

Private Function CheckForExisting(componentType As String,
componentName As String) As Boolean

Dim objAO As AccessObject
Dim objCP As Object
Dim objVBComp As Object

Set objCP = Application.CurrentProject
CheckForExisting = False

Select Case componentType
Case "adModule":
For Each objAO In objCP.AllModules
If objAO.Name = componentName Then
'item already exists
If MsgBox("A module called " & componentName & "
already exists." & vbNewLine & "Do you want to overwrite?", vbYesNo,
"Script Installer") = vbYes Then
' remove module from system
With Application.VBE.ActiveVBProject
For Each objVBComp In .VBComponents
If objVBComp.Name = componentName Then
..VBComponents.Remove objVBComp
Exit For
End If
Next
End With
CheckForExisting = False
Else
CheckForExisting = True
End If
End If
Next

Case "adForm":
For Each objAO In objCP.AllForms
If objAO.Name = componentName Then
'item already exists
If MsgBox("A form called " & componentName & "
already exists." & vbNewLine & "Do you want to overwrite?", vbYesNo,
"Script Installer") = vbYes Then
' remove module from system
'**************************************
'*This is the bit I can't get to work!*
'**************************************
With Application.VBE.ActiveVBProject
For Each objVBComp In .VBComponents
If objVBComp.Name = "Form_" &
componentName Then
..VBComponents.Remove objVBComp
Exit For
End If
Next
End With
CheckForExisting = False
Exit For
Else
' component was not deleted
CheckForExisting = True
Exit For
End If
End If
Next
End Select
End Function

Nov 13 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
rkc
u7***@hotmail.com wrote:
Hi,
I'm currently building an application in Access and as part of this
need to import forms and modules from another database. Some of the
imports will be revisions of existing forms/modules so I need to check
and see they already exist before importing them so I can remove the
old one.
I've figured out how to remove the classes and modules before importing
the revised version but I'm having problems with the forms. I was
hoping to use the AccessObject collection but there doesn't seem to be
a 'remove' function - can anyone shed any light?


There's DoCmd.DeleteObject acTable, "tblByeBye" if that helps.
Nov 13 '05 #2

P: n/a
rkc
rkc wrote:
u7***@hotmail.com wrote:
Hi,
I'm currently building an application in Access and as part of this
need to import forms and modules from another database. Some of the
imports will be revisions of existing forms/modules so I need to check
and see they already exist before importing them so I can remove the
old one.
I've figured out how to remove the classes and modules before importing
the revised version but I'm having problems with the forms. I was
hoping to use the AccessObject collection but there doesn't seem to be
a 'remove' function - can anyone shed any light?


There's DoCmd.DeleteObject acTable, "tblByeBye" if that helps.


Oops. DoCmd.DeleteObject acForm, "frmByeBye"
Nov 13 '05 #3

P: n/a
On 28 Jan 2005 03:42:04 -0800, u7***@hotmail.com wrote:
I've figured out how to remove the classes and modules before importing
the revised version but I'm having problems with the forms. I was
hoping to use the AccessObject collection but there doesn't seem to be
a 'remove' function - can anyone shed any light?


You need DAO to do this rather than ADO. However you can write a macro
to delete it and call this from code, or probably use RunCommand if
you have the patience to work though the doumentation.

David
Nov 13 '05 #4

P: n/a
u7***@hotmail.com wrote:
'**************************************
'*This is the bit I can't get to work!*
'**************************************
With Application.VBE.ActiveVBProject
For Each objVBComp In .VBComponents
If objVBComp.Name = "Form_" &
componentName Then
.VBComponents.Remove objVBComp

--

You might be able to use this procedure to zap a form:

Public Sub RemoveAnAccessObjectFromAnotherFile( _
ByVal FileName As String, _
ByVal ObjectType As AcObjectType, _
ByVal ObjectName As String)

Dim a As Access.Application
Set a = New Access.Application
With a
Select Case Right(FileName, 4)
Case ".adp"
.OpenAccessProject FileName
Case ".mdb"
.OpenCurrentDatabase FileName
Case Else
MsgBox "Please, pass a valid file type!", , "Uh Oh"
.Quit
Exit Sub
End Select
.DoCmd.DeleteObject ObjectType, ObjectName
.Quit
End With
End Sub


--
Lyle

Do you think my sig is too long?
Does size matter?

--
From ADO28.chm

Deprecated Components
Each of the following components is considered obsolete. While these
components are still supported in this release of the Microsoft® Data
Access Components (MDAC), they may be removed in the future. When
writing new applications, you should avoid using these deprecated
components. When modifying existing applications, you are strongly
encouraged to remove any dependency on these components.

ODBC Provider (MSDASQL)
You are strongly encouraged to use one of the native OLE DB Providers
instead of the Microsoft Open Database Connectivity (ODBC) Provider.
Native OLE DB Providers provide better application stability and
performance. Furthermore, native OLE DB Providers will be supported in
the future, whereas MSDASQL will not have any new features added to it,
will not be available on 64-bit, and will not be accessible from the OLE
DB NET Data Provider.

Remote Data Services (RDS)
Remote Data Services (RDS) is a proprietary Microsoft mechanism for
accessing remote data across the Internet or intranet. Microsoft is now
shipping the Microsoft Simple Object Access Protocol (SOAP) Toolkit 2.0
that enables you to access remote data using an open, XML-based
standard. Given the availability of the SOAP Toolkit 2.0, you should
migrate from RDS to SOAP. The SOAP 2.0 Toolkit 2.0 also includes sample
code for remotely accessing Microsoft ActiveX® Data Objects (ADO)
Recordsets.

Jet and Replication Objects (JRO)
The Microsoft Jet OLE DB Provider and other related components were
removed from MDAC 2.6. Microsoft has deprecated the Microsoft Jet
Engine, and plans no new releases or service packs for this component.
As a result, the Jet and Replication Objects (JRO) is being deprecated
in this release and will not be available in any future MDAC releases.

.....
Nov 13 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.