压缩Access数据库 [英] Compessing an Access database

查看:121
本文介绍了压缩Access数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨:


我已经在压缩(压缩)访问数据库的问题上阅读了很多线程

编程,并且一直困惑。我们正在使用Access 2000,我需要代码

,它将以编程方式压缩打开的数据库。 (称为InvoiceManagement.be。


有人可以给我一段代码来执行此操作,或指向一个代码吗?


谢谢


John Baker

解决方案

" John Baker" <乔******** @ comcast.net>在消息中写道

news:cv ******************************** @ 4ax.com ...

嗨:

我已经阅读了很多关于压缩(压缩)的问题的线程
以编程方式访问数据库,以及一直困惑。我们正在使用Access 2000,
我需要能够以编程方式压缩开放数据库的代码。 (名为
" InvoiceManagement.be)。

有人可以给我一段代码来做这件事,还是指向
一个,请呢?

谢谢

John Baker



您不应该尝试压缩其他人可能正在使用的数据库。


我不相信有一个标准的解决方案,因为它取决于

a多个因素:

数据库分为前/后端?

是否有用户级别的安全性?

应该何时发生此操作 - 用户点击或自动安排?


您的代码应该

确定没有人使用数据库进行压缩(''original.mdb'')

将其重命名为''temp.mdb''(make确保没人使用它,或者在紧凑的例行程序中能够获得


带一份名为''copy1.mdb'的副本'

压缩到一个新的数据库''copy2.mdb''

如果一切顺利的话ll,重命名''copy2.mdb''''original.mdb''

删除''copy1.mdb''和''temp.mdb''


Anthony:


我对这方面的访问有点新手。


db是单用户现在,所以没问题。但是,我不确定用于完成我想要的

代码。


我在Access网站上偶然发现了这段代码:


Public Sub CompactDB()

CommandBars(菜单栏)。 _

控制(工具)。 _

控制(数据库实用程序)。 _

控制(压缩和修复数据库......)。 _

accDoDefaultAction


End Sub


我已安装它,可以从名为directlt的按钮运行它,但是想将b $ b与其他一些行为相结合,而且似乎无法将其设置为代码。在一个将执行它的宏中调用




当我通过调试器执行它时,实际代码完成了工作,但它不会执行

当我尝试使用宏设置它时。我想把它变成一个漂亮的简单按钮

按下去除大量多余的数据(旧的历史数据是不必要的)和

压缩文件,但是如果代码不会在宏中执行这很难实现,

因为我不熟练基本代码。


最好


John


" Anthony England" < AE ****** @ oops.co.uk>写道:

" John Baker" <乔******** @ comcast.net>在消息中写道
新闻:cv ******************************** @ 4ax.com .. < blockquote class =post_quotes>嗨:

我已经阅读了一些关于压缩(压缩)问题的线程
以编程方式访问数据库,并且一直困惑。我们正在使用Access 2000,
我需要能够以编程方式压缩开放数据库的代码。 (名为
" InvoiceManagement.be)。

有人可以给我一段代码来做这件事,还是指向
一个,请呢?

谢谢

John Baker



您不应该尝试压缩其他人可能正在使用的数据库。

我不相信有一个标准的解决方案,因为它取决于许多因素:
数据库分为前/后端?
是否有用户级安全性?
这个动作应该何时发生 - 用户点击或自动安排?

您的代码应该确定没有人使用数据库进行压缩(''original.mdb '')
将它重命名为''temp.mdb''(确保没有人使用它,或者能够在紧凑的例程中使用

取一个名为''的副本copy1.mdb''
将此压缩到一个新的数据库''copy2.mdb''
如果一切顺利,重命名''copy2.mdb''''original.mdb''
删除' copy1.mdb和 temp.mdb






"约翰贝克" <乔******** @ comcast.net>在消息中写道

news:u0 ******************************** @ 4ax.com ...

Anthony:

我对这方面的访问有点新手。

数据库现在是单用户,所以没问题。但是,我并不是用来完成我想要的某些代码。

我在Access网站上偶然发现了这段代码:

Public Sub CompactDB()

CommandBars(菜单栏)。 _
控制(工具)。 _
控件(数据库实用程序)。 _
控件(压缩和修复数据库......)。 _
accDoDefaultAction

End Sub

我已经安装了它,可以从名为directlt的按钮运行它,但
想要将其与其他一些行动相结合,似乎无法设置
作为代码。在一个将执行它的宏中调用


当我通过调试器执行它时,实际代码完成了工作,但是当我尝试时它不会执行
并使用宏设置它。我想把它变成一个很好的简单按钮
按下来删除大量多余的数据(旧的历史数据,这是不必要的)和
压缩文件,但如果代码不会在宏中执行,这很难完成,因为我不熟练基本代码。

最好

约翰
安东尼英格兰 < AE ****** @ oops.co.uk>写道:

" John Baker" <乔******** @ comcast.net>在消息中写道
新闻:cv ******************************** @ 4ax.com。 ..

嗨:

我已经阅读了一些关于压缩(压缩)的问题的线程
以编程方式访问数据库,并且有一直困惑。我们正在使用Access 2000,
我需要能够以编程方式压缩开放数据库的代码。 (名为
" InvoiceManagement.be)。

有人可以给我一段代码来做这件事,还是指向
一个,请呢?

谢谢

John Baker



您不应该尝试压缩其他人可能正在使用的数据库。

我不相信有一个标准的解决方案,因为它取决于许多因素:
数据库是分开前/后端吗?是否存在用户级安全性?
应该何时发生此操作 - 用户单击或自动安排?

您的代码应该确定没有人使用数据库被压缩
(''original.mdb'')
将其重命名为''temp.mdb''(确保没有人使用它,或者能够在紧凑时使用
例程)
把一份名为''copy1.mdb''的文件压缩到一个新数据库''copy2.mdb''
如果一切顺利,重命名''copy2.mdb' '''original.mdb''删除''copy1.mdb''和''temp.mdb''




你不会发现很多宏的使用这个新闻组只提供有限的功能 - 大多数工作都是用vba完成的。但无论如何,我从你的回复中得到了

,数据库没有拆分(所以你有一个mdb文件

,里面有表格和表格),你没有安全保障已实施且有
没有多用户问题。

在这种情况下,你可以修改你找到的代码,这样它就是一个功能

,而不是sub:


公共函数CompactDB()

CommandBars(菜单栏)。 _

控制(工具)。 _

控制(数据库实用程序)。 _

控制(压缩和修复数据库......)。 _

accDoDefaultAction


结束功能

然后你可以通过一步RunCode在宏中使用它并填写

函数名称:


= CompactDB()


请注意,这需要是任何一步的最后一步宏为Access需要

在这一步骤中重新启动数据库并且宏在这个期间无法继续。


注意你也可以打开CompactOnClose选项,这样就可以自动完成

数据库了。




Hi:

I have read a number of threads on the issue of compressing (compacting) Access data bases
programmatically, and have been left confused. We are using Access 2000, and I need code
that will programmatically compress an open database. (called "InvoiceManagement.be).

Can someone give me a piece of code that will do this, or a pointer to one, please?

Thanks

John Baker

解决方案

"John Baker" <jo********@comcast.net> wrote in message
news:cv********************************@4ax.com...

Hi:

I have read a number of threads on the issue of compressing (compacting)
Access data bases
programmatically, and have been left confused. We are using Access 2000,
and I need code
that will programmatically compress an open database. (called
"InvoiceManagement.be).

Can someone give me a piece of code that will do this, or a pointer to
one, please?

Thanks

John Baker


You should not be trying to compact a database which others might be using.

I don''t believe there is one standard solution to this because it depends on
a number of factors:
Is the database split front/back end?
Is there user-level security?
When should this action happen - by user click or scheduled automatically?

Your code should
establish that no-one is using the database to be compacted (''original.mdb'')
rename it to ''temp.mdb'' (makes sure no-one is using it, or will be able to
during compact routine)
take a copy called ''copy1.mdb''
compact this to a new database ''copy2.mdb''
if all goes well, rename ''copy2.mdb'' ''original.mdb''
delete ''copy1.mdb'' and ''temp.mdb''


Anthony:

I am a bit of a neophyte with this aspect of access.

The db is single user right now, so no problem there. However, I am not certain of the
code to use to accomplish what I want.

I stumbled on this code in the Access Web site:

Public Sub CompactDB()

CommandBars("Menu Bar"). _
Controls("Tools"). _
Controls("Database utilities"). _
Controls("Compact and repair database..."). _
accDoDefaultAction

End Sub

I have installed it, and can run it from a button called directlt, but would like to
combine it with some other actions, and don''t appear to be able to set up as "code" call
in a macro that will execute it.

The actual code does the job when i execute it through the debugger, but it wont execute
when I try and set it up using a macro. I would like to make it into an nice easy button
press to remove a lot of excess data (old historical data that is unnecessary) and
compress the files, but if the code wont execute in a macro this is hard to accomplish,
since Im not skilled in Basic code.

Best

John

"Anthony England" <ae******@oops.co.uk> wrote:

"John Baker" <jo********@comcast.net> wrote in message
news:cv********************************@4ax.com.. .

Hi:

I have read a number of threads on the issue of compressing (compacting)
Access data bases
programmatically, and have been left confused. We are using Access 2000,
and I need code
that will programmatically compress an open database. (called
"InvoiceManagement.be).

Can someone give me a piece of code that will do this, or a pointer to
one, please?

Thanks

John Baker


You should not be trying to compact a database which others might be using.

I don''t believe there is one standard solution to this because it depends on
a number of factors:
Is the database split front/back end?
Is there user-level security?
When should this action happen - by user click or scheduled automatically?

Your code should
establish that no-one is using the database to be compacted (''original.mdb'')
rename it to ''temp.mdb'' (makes sure no-one is using it, or will be able to
during compact routine)
take a copy called ''copy1.mdb''
compact this to a new database ''copy2.mdb''
if all goes well, rename ''copy2.mdb'' ''original.mdb''
delete ''copy1.mdb'' and ''temp.mdb''





"John Baker" <jo********@comcast.net> wrote in message
news:u0********************************@4ax.com...

Anthony:

I am a bit of a neophyte with this aspect of access.

The db is single user right now, so no problem there. However, I am not
certain of the
code to use to accomplish what I want.

I stumbled on this code in the Access Web site:

Public Sub CompactDB()

CommandBars("Menu Bar"). _
Controls("Tools"). _
Controls("Database utilities"). _
Controls("Compact and repair database..."). _
accDoDefaultAction

End Sub

I have installed it, and can run it from a button called directlt, but
would like to
combine it with some other actions, and don''t appear to be able to set up
as "code" call
in a macro that will execute it.

The actual code does the job when i execute it through the debugger, but
it wont execute
when I try and set it up using a macro. I would like to make it into an
nice easy button
press to remove a lot of excess data (old historical data that is
unnecessary) and
compress the files, but if the code wont execute in a macro this is hard
to accomplish,
since Im not skilled in Basic code.

Best

John

"Anthony England" <ae******@oops.co.uk> wrote:

"John Baker" <jo********@comcast.net> wrote in message
news:cv********************************@4ax.com. ..

Hi:

I have read a number of threads on the issue of compressing (compacting)
Access data bases
programmatically, and have been left confused. We are using Access 2000,
and I need code
that will programmatically compress an open database. (called
"InvoiceManagement.be).

Can someone give me a piece of code that will do this, or a pointer to
one, please?

Thanks

John Baker


You should not be trying to compact a database which others might be
using.

I don''t believe there is one standard solution to this because it depends
on
a number of factors:
Is the database split front/back end?
Is there user-level security?
When should this action happen - by user click or scheduled automatically?

Your code should
establish that no-one is using the database to be compacted
(''original.mdb'')
rename it to ''temp.mdb'' (makes sure no-one is using it, or will be able to
during compact routine)
take a copy called ''copy1.mdb''
compact this to a new database ''copy2.mdb''
if all goes well, rename ''copy2.mdb'' ''original.mdb''
delete ''copy1.mdb'' and ''temp.mdb''



You won''t find much use of macros in this newsgroup as they only offer
limited functionality - most work is done with vba. But anyway, I take it
from your reply that the database is not split (so you have one mdb file
with tables and forms in it), you have no security implemented and there are
no multi-user issues.
In that case you can just modify the code you found so that it is a function
, rather than a sub:

Public Function CompactDB()

CommandBars("Menu Bar"). _
Controls("Tools"). _
Controls("Database utilities"). _
Controls("Compact and repair database..."). _
accDoDefaultAction

End Function
Then you can use this in a macro by having a step of RunCode and fill in the
function name:

=CompactDB()

Note that this needs to be the final step of any macro as Access needs to
re-start the database during this step and a macro cannot continue during
this.

Note that you could also just switch on the CompactOnClose option, so the
database is automatically compcted.




这篇关于压缩Access数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆