//创建Access
    AccessApplication.Connect;
    AccessApplication.NewCurrentDatabase('c:\a.mdb');
    AccessApplication.CurrentDb.NewPassword('""','clt');
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    AccessApplication.CloseCurrentDatabase;
    AccessApplication.Disconnect;
用NewPassword但提示密码错误。
还有我还试过:
NewPassword('','clt');
NewPassword('''' + '' + '''','clt');
还是不行。
不知有谁能帮我。

解决方案 »

  1.   

    http://www.delphibbs.com/delphibbs/dispq.asp?lid=1601151
    //=============================================================================
    // Procedure: CreateAccessFile
    // Author   : ysai
    // Date     : 2003-01-27
    // Arguments: FileName:String;PassWord:string=''
    // Result   : boolean
    //=============================================================================
    function CreateAccessFile(FileName:String;PassWord:string=''):boolean;
    //建立Access文件,如果文件存在则失败
    var
      STempFileName:string;
      vCatalog:OleVariant;
    begin
      STempFileName:=GetTempPathFileName;
      try
        vCatalog:=CreateOleObject('ADOX.Catalog');
        vCatalog.Create(format(SConnectionString,[STempFileName,PassWord]));
        result:=CopyFile(PChar(STempFileName),PChar(FileName),True);
        DeleteFile(STempFileName);
      except
        result:=false;
      end;
    end;
      

  2.   

    这种实现是COM晚绑定,也可以先导入ADOX类型库,用ADO大概做不了这种事。
      

  3.   

    这AccessApplication是用delphi导入的为access_Tlb下的一个控件。
    还有NewPassword方法在dao35.hlp帮助文件中可以找到的
    我根据上面的说明来做,就是提示密码错误。
    不知有没有人通过这个方式解决?
      

  4.   

    NewPassword Method ExampleThis example asks the user for a new password for user Pat Smith. If the input is a string between 1 and 14 characters long, the example uses the NewPassword method to change the password. The user must be logged on as Pat Smith or as a member of the Admins group.Sub NewPasswordX()    Dim wrkDefault As Workspace
        Dim usrNew As User
        Dim grpNew As Group
        Dim grpMember As Group
        Dim strPassword As String    ' Get default workspace.
        Set wrkDefault = DBEngine.Workspaces(0)    With wrkDefault        ' Create and append new user.
            Set usrNew = .CreateUser("Pat Smith", _
                "abc123DEF456", "Password1")
            .Users.Append usrNew        ' Create and append new group.
            Set grpNew = .CreateGroup("Accounting", _
                "UVW987xyz654")
            .Groups.Append grpNew        ' Make the new user a member of the new group.
            Set grpMember = usrNew.CreateGroup("Accounting")
            usrNew.Groups.Append grpMember        ' Ask user for new password. If input is too long, ask 
            ' again.
            Do While True
                strPassword = InputBox("Enter new password:")
                Select Case Len(strPassword)
                    Case 1 To 14
                        usrNew.NewPassword "Password1", strPassword
                        MsgBox "Password changed!"
                        Exit Do
                    Case Is > 14
                        MsgBox "Password too long!"
                    Case 0
                        Exit Do
                End Select
            Loop        ' Delete new User and Group objects because this
            ' is only a demonstration.
            .Users.Delete "Pat Smith"
            .Groups.Delete "Accounting"    End WithEnd Sub
      

  5.   

    通过adoconnection控件连接数据库是会出现“数据连接属性”对话框,在“所有”标签下的Jet OLEDB:Database Password属性,将其值修改为数据库的密码。
    还有一个比较重要的问题是在“连接”标签下选中空白密码。还可以带密码压缩:dao.CompactDatabase(FileName,TempFile,'',0,';pwd=123456789'); 还有Diamond Access也能够给Access数据库加密码
      

  6.   

    Function SetMDBPassWord(FileName:String;OldPWD:String;NewPWD:String):Boolean;
    var
       TempStr:String;
    begin
      with Frm_NoteBook.ADOConnection1 do begin
           Connected:=false;
           ConnectionString:='Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin;' +
              'Data Source='+ FileName +
              ';Mode=Share Deny Read|Share Deny Write;Extended Properties="";' +
              'Jet OLEDB:System database="";' +
              'Jet OLEDB:Registry Path="";' +
              'Jet OLEDB:Database Password='+ OldPWD +';'+
              'Jet OLEDB:Engine Type=5;' +
              'Jet OLEDB:Database Locking Mode=1;' +
              'Jet OLEDB:Global Partial Bulk Ops=2;' +
              'Jet OLEDB:Global Bulk Transactions=1;' +
              'Jet OLEDB:New Database Password="";' +
              'Jet OLEDB:Create System Database=False;' +
              'Jet OLEDB:Encrypt Database=False;' +
              'Jet OLEDB:Don''t Copy Locale on Compact=False;' +
              'Jet OLEDB:Compact Without Replica Repair=False;' +
              'Jet OLEDB:SFP=False';
          try
             connected:=true;
             if trim(OldPWD)='' then OldPWD:='null';
             if trim(NewPWD)='' then NewPWD:='null';
             TempStr:='ALTER Database Password '+ NewPWD + '  ' + OldPWD;
             Execute(TempStr,cmdText,[eoExecuteNoRecords]);
             result:=true;
          except
             msgbox('数据文件处理发生错误!','',16);
             result:=false;
          end;
      end;
    end;
      

  7.   

    CompactDatabase 这个方法是用来压缩access数据库?
    那NewPassword到底有没有用?
    照帮助上讲的可以1、加密码;2、修改密码;3、撤消密码
    但是就是不能加密码。
      

  8.   

    试呢一下CompactDatabase ,加密码是可以,但是要多一个文件出来。
    还有,不知有没有人试过createdatabase,
    我试呢一下,提示什么smia?(不知名字对不对)to  anh(hananying)
    我是要在delphi中,创建access是对access加上密码。不用用户操作的。