如何通过代码更改数据库密码
时 间:2011-03-11 00:00:00
作 者:风行 ID:16058 城市:江阴
摘 要:设置数据库密码
下面的 ADO 示例假定当前数据库中包含一个空数据库密码。(要以独占方式打开数据库)
注: 引用确保已选中 Microsoft ActiveX 数据对象 2.x 库 复选框。
创建一个模块,键入以下代码
正 文:
Option Explicit
Sub ADOAddPW()
Dim cn As ADODB.Connection
Dim newpassword As String
Dim NotValid As Integer
Dim sqlExecStr As String
Set cn = CurrentProject.Connection
On Error Resume Next
' Test to see if the database is open exclusively.
If cn.Mode <> 12 Then
MsgBox "Your database is not opened exclusively", vbCritical
Exit Sub
End If
RetryPassword:
newpassword = InputBox("Please enter new database password", "Database Password" _
, "New Database Password")
' Select case for inputbox.
Select Case newpassword
' Case where the cancel button was pressed.
Case "New Database Password"
MsgBox "No Database password set"
Exit Sub
' Case where the OK button was pressed without entering data.
Case ""
NotValid = MsgBox("You have not entered a valid password, or clicked the cancel button" & Chr(10) & Chr(13) & _
"Do you want to change the database password?", vbCritical + vbYesNo)
If NotValid = 6 Then
GoTo RetryPassword
Else
Exit Sub
End If
'If any data is entered other than the default value.
Case Else
sqlExecStr = "Alter Database Password " & newpassword & "``"
CurrentProject.Connection.Execute sqlExecStr
MsgBox "Database password has been set"
End Select
End Sub
关闭并重新打开数据库。请注意系统将提示您输入数据库密码。
Access软件网官方交流QQ群 (群号:54525238) Access源码网店
常见问答:
技术分类:
源码示例
- 【源码QQ群号19834647...(12.17)
- Access自定义消息盒Msg...(04.28)
- Access怎么按每个月份里面...(03.09)
- Access怎么按季度来统计人...(02.26)
- Access怎么按年龄段来统计...(01.26)
- 【Access高效办公】上一年...(12.29)
- 用Access连续窗体制作的树...(11.03)
- 【Access高效办公】上一年...(10.30)
- Access制作的RGB转CM...(09.22)
- Access制作的RGB调色板...(09.15)
学习心得
最新文章
- 将bit字段的Null值更新为Fa...(06.01)
- 用VBA批量更改SQL SERVE...(05.30)
- 用SQL代码更改SQL Serve...(05.29)
- Access快速开发平台--图片附...(05.29)
- 如何用VBA检查表有没有设置主键(05.28)
- 用VBA来指定图表中横坐标/纵坐标...(05.25)
- 还在凭感觉建表?Access建表思...(05.25)
- ACCESS视频手机上看瞎眼?用电...(05.24)
- 用SSMS将ACCESS中的表导入...(05.21)
- 自动编号用不好,系统迟早要乱!Ac...(05.21)


.gif)
