Program: Create, Compress Access database and modify password demo

Source: Internet
Author: User
Tags chr modify return access database create database
access| Program | create | data | database | compress
* --------------------------------------------
* Program: Create, Compress Access database and modify password demo
* Design: Red rain
* --------------------------------------------
Local Lcmdbfile, Lcretustr
Lcmdbfile = [C:\Temp\TestCreaMdbFile.mdb]
LCPSWD1 = [Test1]
LCPSWD2 = [Test2]
LCPSWD3 = [Test3]
LCRETUSTR = [Create, compress Access database and modify password Demo:] + Chr (13)

If Createmdb (Lcmdbfile, LCPSWD1)
Lcretustr = Lcretustr + Chr (13) + [1, CREATE DATABASE Success-Password:] + lcPswd1
If Compactmdb (Lcmdbfile, LCPSWD1, LCPSWD2)
Lcretustr = Lcretustr + Chr (13) + [2, Compress and modify password Success-Password:] + lcPswd2
If Changemdbpassword (Lcmdbfile, LCPSWD2, LCPSWD3)
Lcretustr = Lcretustr + Chr (13) + [3] Modify database password successfully-password:] + lcPswd3
Else
Lcretustr = Lcretustr + Chr (13) + [3] Failed to modify database password individually]
Endif
Else
Lcretustr = Lcretustr + Chr (13) + [2, compressing and modifying password failed]
Endif
Else
Lcretustr = Lcretustr + Chr (13) + [1, failed to create database]
Endif

= MessageBox (Lcretustr, 0+64+0, [red rain hint])
Return

* --------------------------------------------
Function Createmdb (Tcmdbfile, TCPSWDSTR)
* Create an Access database file (. mdb)
Local IsOK
IsOK =. F.
Tcmdbfile = IIF (Type ([Tcmdbfile]) =[c], Tcmdbfile, [])
Tcpswdstr = IIF (Type ([tcpswdstr]) =[c], TCPSWDSTR, [])
If File (Tcmdbfile)
Erase (Tcmdbfile)
Endif
If! File (Tcmdbfile)
IsOK =. T.
Local loengine, Lcolderror, Lccmdstrs
Lcolderror = ON ([ERROR])
On Error IsOK =. F.
Locatalog = CreateObject ([ADOX. Catalog])
Lccmdstrs = [provider=microsoft.jet.oledb.4.0];
+ [;D ata source=] + tcmdbfile;
+ [; Jet oledb:database password=] + tcpswdstr
Locatalog.create (Lccmdstrs)
Release Locatalog
Locatalog = Null
On Error &lcolderror.
Endif
Return IsOK and File (tcmdbfile)
Endfunc

* --------------------------------------------
Function Compactmdb (Tcmdbfile, TCOLDPSWD, TCNEWPSWD)
* Compress Access database and set password
Local IsOK
IsOK =. F.
Tcmdbfile = IIF (Type ([Tcmdbfile]) =[c], Tcmdbfile, [])
TCOLDPSWD = IIF (Type ([tcoldpswd]) =[c], tcoldpswd, [])
TCNEWPSWD = IIF (Type ([tcnewpswd]) =[c], tcnewpswd, TCOLDPSWD)
If File (Tcmdbfile)
IsOK =. T.
Local loengine, Lctmpfile, Lcolderror, Lccompoldstr, Lccompnewstr
Lcolderror = ON ([ERROR])
On Error IsOK =. F.
Lctmpfile = Addb (Justpath (tcmdbfile)) + Subs (Sys (2015), 3) + [. mdb]
Rename (Tcmdbfile) to (Lctmpfile)
If! File (tcmdbfile) and file (Lctmpfile)
LCCOMPOLDSTR = [provider=microsoft.jet.oledb.4.0];
+ [;D ata source=] + lctmpfile;
+   [; Jet oledb:database password=] + tcoldpswd
LCCOMPNEWSTR = [provider=microsoft.jet.oledb.4.0];
+ [;D ata source=] + tcmdbfile;
+   [; Jet oledb:database password=] + tcnewpswd
Loengine = CreateObject ([JRO. JetEngine])
Loengine.compactdatabase (Lccompoldstr, LCCOMPNEWSTR)
Release Loengine
Loengine = Null
If File (Tcmdbfile)
Erase (Lctmpfile)
Else
Rename (Lctmpfile) to (Tcmdbfile)
Endif
Else
IsOK =. F.
Endif
On Error &lcolderror.
Endif
Return IsOK and File (tcmdbfile)
Endfunc

* --------------------------------------------
Function Changemdbpassword (Tcmdbfile, TCOLDPSWD, TCNEWPSWD)
* Modify Access Database password, you must open the database exclusively, make sure no other programs use the database before use
Local IsOK
IsOK =. F.
LCRETUSTR = []
Tcmdbfile = IIF (Type ([Tcmdbfile]) =[c], Tcmdbfile, [])
TCOLDPSWD = IIF (Type ([tcoldpswd]) =[c], tcoldpswd, [])
TCNEWPSWD = IIF (Type ([tcnewpswd]) =[c], tcnewpswd, [])
If File (Tcmdbfile)
IsOK =. T.
Local Loadodb, Lcolderror
Lcolderror = ON ([ERROR])
On Error IsOK =. F.
Loadodb = CreateObject ([ADODB. Connection])
Loadodb.mode = 12
Loadodb.provider = [Microsoft.Jet.OLEDB.4.0]
Loadodb.properties ([Jet oledb:database Password]) = TCOLDPSWD
Loadodb.open ([Data source=] + tcmdbfile)
Loadodb.execute (' ALTER DATABASE PASSWORD [' + tcnewpswd + '] [' + tcoldpswd + '] ')
Loadodb.close
Release Loadodb
Loadodb = Null
On Error &lcolderror.
Endif
Return IsOK
Endfunc

* --------------------------------------------



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.