|
-
Sep 11th, 2006, 05:32 PM
#1
Thread Starter
Lively Member
[02/03] Clean up Access Database
I have an Access database which the user might want to clean up to start fresh from time to time, how can I accomplish this?
Im working with the Jet engine btw.
-
Sep 11th, 2006, 05:38 PM
#2
Re: [02/03] Clean up Access Database
Do you mean like recreating just the database schema or a compact and repair?
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Sep 11th, 2006, 05:40 PM
#3
Thread Starter
Lively Member
Re: [02/03] Clean up Access Database
 Originally Posted by RobDog888
Do you mean like recreating just the database schema or a compact and repair?
I guess it would be a clean recreation of the existing database. There is a consecutive number (key) which is incrementing with every interaction, and the user might want to restart that number back to 1.
-
Sep 11th, 2006, 05:48 PM
#4
Re: [02/03] Clean up Access Database
Well if there are records still in the table then you culdnt reset it back to one so I take it would be a blank database with just the table definitions and queries ets. (schema).
You could use the TransferDatabase method to export a table to another access database.
VB Code:
'Using the Access Object Model
'Repeat for each objecvt to be replicated to the new blank db
'Change constants to .NET
Application.DoCmd.TransferDatabase acExport, "Microsoft Access", "C:\RobDog888New.mdb", acTable, "Table1", "Table1", True
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Sep 11th, 2006, 06:00 PM
#5
Thread Starter
Lively Member
Re: [02/03] Clean up Access Database
 Originally Posted by RobDog888
Well if there are records still in the table then you culdnt reset it back to one so I take it would be a blank database with just the table definitions and queries ets. (schema).
You could use the TransferDatabase method to export a table to another access database.
VB Code:
'Using the Access Object Model
'Repeat for each objecvt to be replicated to the new blank db
'Change constants to .NET
Application.DoCmd.TransferDatabase acExport, "Microsoft Access", "C:\RobDog888New.mdb", acTable, "Table1", "Table1", True
Thanks Rob, how do I import the Access Object Model?
Another question, would I need a clean version of the same file?
-
Sep 11th, 2006, 06:08 PM
#6
Re: [02/03] Clean up Access Database
What this method does is to copy each object individually one at a time with just the table definition only or if you want you can copy the data too.
so if you have 5 tables then you would have to make 5 calls passing each table name separately.
There is another method call that can create the blank empty database file -
Application.NewCurrentDatabase "C:\RobDog888.mdb"
But then your current db will be the empty one so your TransferDatabase call would be turned into an Import call.
Add a reference or use Late Binding if the Access version is or may change.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Sep 11th, 2006, 07:00 PM
#7
Re: [02/03] Clean up Access Database
VB Code:
Option Explicit On
Option Strict On
'Add a reference to MS Access xx.0 Object Library
Imports Microsoft.Office.Interop
Public Class Form1
Inherits System.Windows.Forms.Form
Private moApp As Access.Application
Private Sub frmClients_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
moApp = DirectCast(CreateObject("Access.Application"), Access.Application)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
moApp.NewCurrentDatabase "C:\RobDog888New.mdb"
moApp.DoCmd.TransferDatabase Access.AcDataTransferType.acImport, "Microsoft Access", "C:\RobDog888.mdb", Access.AcDataObjectType.acDataTable, "Table1", "Table1", True
'More object calls etc.
'...
End Sub
End Class
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Sep 27th, 2006, 08:25 AM
#8
Thread Starter
Lively Member
Re: [02/03] Clean up Access Database
Thanks Rob, I now have a problem with casting the Access.acDataObjectType as Access.acObjectType in the line:
VB Code:
moApp.DoCmd.TransferDatabase(Access.AcDataTransferType.acImport, "Microsoft Access", "C:\RobDog888.mdb", [B][COLOR=RED]Access.AcDataObjectType.acDataTable[/COLOR][/B], "Table1", "Table1", True)
What am I missing? Thanks again.
-
Sep 27th, 2006, 02:32 PM
#9
Re: [02/03] Clean up Access Database
Not sure how that changed but it should be in my post as
Access.AcObjectType.acTable
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|