473,705 Members | 2,449 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Programmaticall y remove a form from Access 2000

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(sc riptID As Integer) As Boolean
Dim rsComponents As New ADODB.Recordset
Dim o_Conn As New ADODB.Connectio n
Dim m_Conn_Str As String
Dim strSQL As String

On Error GoTo ImportScript_Er r

m_Conn_Str = "Provider=Micro soft.Jet.OLEDB. 4.0;Data Source = " &
DEV_DB & ";User ID=""admin"";Pa ssword="""";"
o_Conn.CursorLo cation = adUseClient
o_Conn.Connecti onString = m_Conn_Str
o_Conn.Open

With rsComponents
strSQL = "SELECT tblScript.Scrip tName, tblScript.Scrip tDesc,
tblScript.Acces sLevel, tblScriptCompon ent.ComponentTy pe,
tblScriptCompon ent.ComponentNa me, tblScriptCompon ent.EditDate " & _
"FROM tblScript INNER JOIN tblScriptCompon ent ON
tblScript.Scrip tID = tblScriptCompon ent.ScriptID WHERE
tblScript.Scrip tID = " & scriptID & ";"

..Open strSQL, o_Conn, adOpenForwardOn ly, adLockOptimisti c
While Not rsComponents.EO F
If .Fields(3) = "adForm" Then
If Not (CheckForExisti ng(.Fields(3), .Fields(4))) Then
ImportAccessFor m (.Fields(4))
End If
ElseIf .Fields(3) = "adModule" Then
If Not (CheckForExisti ng(.Fields(3), .Fields(4))) Then
ImportModule (.Fields(4))
End If
End If
..MoveNext
Wend
..MoveFirst
strSQL = "INSERT INTO tblInstalledScr ipts (scriptName,
scriptDesc, accessLevel, ModifiedDate) VALUES " & _
"(""" & .Fields(0) & """,""" & .Fields(1) &
"""," & .Fields(2) & ",#" & .Fields(5) & "#);"
CurrentDb().Exe cute strSQL
End With
ImportScript_Ex it:
ImportScript = True
Exit Function

ImportScript_Er r:
ImportScript = False
Exit Function
Resume
End Function

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

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

Private Function CheckForExistin g(componentType As String,
componentName As String) As Boolean

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

Set objCP = Application.Cur rentProject
CheckForExistin g = False

Select Case componentType
Case "adModule":
For Each objAO In objCP.AllModule s
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 .ActiveVBProjec t
For Each objVBComp In .VBComponents
If objVBComp.Name = componentName Then
..VBComponents. Remove objVBComp
Exit For
End If
Next
End With
CheckForExistin g = False
Else
CheckForExistin g = 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 .ActiveVBProjec t
For Each objVBComp In .VBComponents
If objVBComp.Name = "Form_" &
componentName Then
..VBComponents. Remove objVBComp
Exit For
End If
Next
End With
CheckForExistin g = False
Exit For
Else
' component was not deleted
CheckForExistin g = True
Exit For
End If
End If
Next
End Select
End Function

Nov 13 '05 #1
4 3973
rkc
u7***@hotmail.c om 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.DeleteObj ect acTable, "tblByeBye" if that helps.
Nov 13 '05 #2
rkc
rkc wrote:
u7***@hotmail.c om 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.DeleteObj ect acTable, "tblByeBye" if that helps.


Oops. DoCmd.DeleteObj ect acForm, "frmByeBye"
Nov 13 '05 #3
On 28 Jan 2005 03:42:04 -0800, u7***@hotmail.c om 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
u7***@hotmail.c om wrote:
'************** *************** *********
'*This is the bit I can't get to work!*
'************** *************** *********
With Application.VBE .ActiveVBProjec t
For Each objVBComp In .VBComponents
If objVBComp.Name = "Form_" &
componentName Then
.VBComponents.R emove objVBComp

--

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

Public Sub RemoveAnAccessO bjectFromAnothe rFile( _
ByVal FileName As String, _
ByVal ObjectType As AcObjectType, _
ByVal ObjectName As String)

Dim a As Access.Applicat ion
Set a = New Access.Applicat ion
With a
Select Case Right(FileName, 4)
Case ".adp"
.OpenAccessProj ect FileName
Case ".mdb"
.OpenCurrentDat abase FileName
Case Else
MsgBox "Please, pass a valid file type!", , "Uh Oh"
.Quit
Exit Sub
End Select
.DoCmd.DeleteOb ject 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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
2861
by: ALthePal | last post by:
Hi, I'm not sure if we are able to or even how to loop through the web forms in a VB.NET project during design time. In MSAccess we are able to go through the database -> forms collection and loop through all the forms in a database and pull information about the form (controls and properties). We would need to do the same in our VB.NET project; loop through the project and get the web form's control and property information...
8
16664
by: deko | last post by:
I'm trying to find a way to set form/control properties programmatically. In a nut shell: 1. Open a database 2. Open a form in design view 3. Do something like this: For Each prp In frm.Properties If prp.Name = rst!PropName Then prp = rst!ChangeTo
1
3988
by: ADAM BETCHER | last post by:
Hi: I am using TreeView in a Microsoft Access 2000 form. I can create the tree, populate it and select items. Now I want to Programmatically select and highlight a node on the tree based upon a value selected elsewhere in the form. Can someone explain how to do the above, or send me a reference that explains TreeView in more detail? --
6
13454
by: Null Reference | last post by:
Anybody here who can explain or point me to a link ? I wish to create a blank MS Access DB file programmatically using C# . Thanks, nfs
3
4603
by: Tzvika | last post by:
Hi, Is there a way to programmatically add/remove windows components in c# or in any other language What is the API fro that?
13
2573
by: Alexandra | last post by:
Hi, I have a hidden system file that I need to read. I am logged in as an administrator. I can not change the file attributes using the windows explorer.
5
6816
by: Carlo Marchesoni | last post by:
From an aspx page (A.aspx) I open another one (B.aspx - for table lookup). When the user selects an entry in B.aspx I would like to force a button's event in A.aspx to be fired. I guess the only way is using javascript - does anybody have a sample for this ? Thanks
32
3682
by: deko | last post by:
I have a popup form with a textbox that is bound to a memo field. I've been warned about memo fields so I'm wondering if I should use this code. Is there any risk with changing the form's RecordSource like this? Am I asking for trouble doing this with a memo field? Thanks in advance. Private Sub cmdNextNote_Click() Dim lngNid As Long If Me.Dirty Then DoCmd.RunCommand acCmdSaveRecord
5
4459
by: DonnaL | last post by:
I'm using Access 2000, but this question likely pertains to any version of Access. Simply put, is there a programmatic way of inserting a new Query in whatever master system table stores these (maybe QueryDefs?), so I wouldn't have to use the IDE and open Access to do it? Here's more information if that helps: I can open Access itself and create a Query. I can save it and name it something meaningful. I can then execute that query just by...
0
8689
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9273
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9030
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8979
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7893
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6605
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4439
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3137
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2486
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.