怎样用DAO给access数据库设置密码

 我来答
ta...4@163.com
2017-10-26 · TA获得超过1019个赞
知道答主
回答量:71
采纳率:22%
帮助的人:39.1万
展开全部
使用DAO方式改变密码

Private Sub cmdChangeDAO_Click()
Dim strNewPassword As String

'Check if a database is open
If fDC Then 'using data control
'Get new password
strNewPassword = InputBox("Please type in new password. Leave blank to remove password protection")
'Change password
Data1.Database.NewPassword strPassword, strNewPassword
Else
If strSource = "" Then
MsgBox "No current database open"
Else
'Get new password
strNewPassword = InputBox("Please type in new password. Leave blank to remove password protection")
'Change password
db.NewPassword strPassword, strNewPassword
End If
End If
'Update variable
strPassword = strNewPassword
WriteCaptions fDAO
End Sub

使用ADO方式改变密码

Private Sub cmdChangeADO_Click()
Dim strNewPassword As String
Dim strsql As String

If fDC Then 'using data control
'cannot change password from ADODC
MsgBox "You have opened the database with ADODC data control. This control is not capable of changing the database password." & vbCrLf & "Use ADO Code connection string to achieve this."
Else
'Check if a database is open
If strSource = "" Then
MsgBox "No current database open"
Else
'Get new password
strNewPassword = InputBox("Please type in new password. Leave blank to remove password protection")
'Change password
If strNewPassword = "" Then 'Remove password
strsql = "ALTER Database Password `` " & strPassword
Else
If strPassword = "" Then 'no current password
strsql = "ALTER Database Password " & strNewPassword & " ``"
Else 'straight forward change
strsql = "ALTER Database Password " & strNewPassword & " " & strPassword
End If
End If
cnn.Execute strsql
End If
End If
'Update variable
strPassword = strNewPassword
WriteCaptions fDAO
End Sub
本回答被网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式