Office中國論壇/Access中國論壇

標(biāo)題: 設(shè)置ACCESS的信任位置 [打印本頁]

作者: andymark    時(shí)間: 2012-6-23 23:03
標(biāo)題: 設(shè)置ACCESS的信任位置
       在2007 和 2010 版本中打開數(shù)據(jù)庫文件,系統(tǒng)都會(huì)彈出安全警告提示框,對(duì)于用戶能確定安全的文件,可以新建一個(gè)文件夾集中存放在那里。然后設(shè)為信任位置,這樣打開該文件夾的數(shù)據(jù)庫就不會(huì)出現(xiàn)煩人的提示框了。
    我們可以按下面的步驟手動(dòng)添加 :【文件】>>【選項(xiàng)】>>【信任中心】>>【信任中心設(shè)置】 然后選擇右邊的【受信任位置】
    我們也可以用代碼來實(shí)現(xiàn)上面的功能,使自已的程序更加趣味化

  1. Dim strRegKEY As String
  2. Dim APP_KEY As String
  3. Dim Reg As New clsRegistry
  4. Dim FrmState As Integer           '(1--增加,2--修改)
  5. Dim FrmLocation As Integer        '傳遞參數(shù)

  6. Private Sub Form_Load()

  7.    APP_KEY = "Software\Microsoft\Office" & Format(Application.Version, "##,##0.0") & _
  8.              "\Access\Security\Trusted Locations\Location"
  9.    strRegKEY = "HKEY_CURRENT_USER" & APP_KEY
  10.    
  11.    FrmState = SysState
  12.    FrmLocation = SysLocation
  13.    If FrmState = 2 Then
  14.       Call ShowBill(FrmLocation)
  15.       Else
  16.       Call AddBill
  17.    End If
  18.       
  19. End Sub

  20. Private Sub Form_Unload(Cancel As Integer)
  21.    SysState = 0
  22.    SysLocation = 0
  23.    Set Reg = Nothing
  24. End Sub

  25. Private Sub CmdOK_Click()                       '確定
  26.    Dim IntAllow As Integer
  27.    Dim strPath As String
  28.    If Len(Me.TxtFolderPath) = 0 Then
  29.       Me.TxtFolderPath.SetFocus
  30.       MsgBox "請(qǐng)選擇受信任文件夾"
  31.       Exit Sub
  32.     End If
  33.    
  34.     If Len(Me.TxtDescription) = 0 Then
  35.       Me.TxtDescription.SetFocus
  36.       MsgBox "說明不能為空"
  37.       Exit Sub
  38.     End If
  39.    
  40.    If Right(Me.TxtFolderPath, 1) <> "" Then
  41.       strPath = Me.TxtFolderPath & ""
  42.       Else
  43.       strPath = Me.TxtFolderPath
  44.    End If
  45.    If Me.ChkAllow = True Then
  46.       IntAllow = 1
  47.       Else
  48.       IntAllow = 0
  49.    End If
  50.    If FrmState <> 2 Then
  51.       FrmLocation = GetUnUsedLocation
  52.    End If
  53.    Call SetTrustedLocation(FrmLocation, strPath, Trim(Me.TxtDescription), CStr(Now), IntAllow)
  54.    If FrmState = 2 Or FrmState = 1 Then
  55.      Call Forms("受信任位置").ShowBill
  56.      DoCmd.Close acForm, Me.Name
  57.    End If
  58. End Sub
復(fù)制代碼
完整示例參考附件

[attach]49467[/attach]
作者: Henry D. Sy    時(shí)間: 2012-6-23 23:07
謝謝分享,收藏!
作者: t小寶    時(shí)間: 2012-6-23 23:42
值得學(xué)習(xí)~!
作者: zhuyiwen    時(shí)間: 2012-6-24 06:43
謝謝分享
作者: xie62    時(shí)間: 2012-6-24 07:17
謝謝分享
作者: xie62    時(shí)間: 2012-6-24 09:44
謝謝分享
作者: ithink2012    時(shí)間: 2012-6-24 09:46
很好的例子,之前一直想要的,只是苦于自己寫不來啊
作者: pengxming    時(shí)間: 2014-7-7 10:49
謝謝分享




歡迎光臨 Office中國論壇/Access中國論壇 (http://m.mzhfr.cn/) Powered by Discuz! X3.3