Problem using TransferDatabase method from Password Protected database
Hi All,
I have two databases and both databases (Source database and destination database) are password protected. I'm importing the data from one Access database to another database using following VBA Code. While importing it's prompting for the password which I don't want. I have tried lot of options but no success. Please help...
Below is the code for your reference.
Code:
Private Sub ImportFromAccess(sDatabaseID As String, sSourceTblNm As String, sDestTblNm As String)
On Error GoTo ErrHandler
Dim objApp As Object
Dim strDeleteSQL As String
Dim priorYear As String
Dim strSourceDatabasePathNName As String 'Source Database Path and Name, from where data need to imported
Dim strSourceDatabasePassword As String
Dim strDestDatabasePathNName As String 'Destination Database Path and Name, where data need to exported
Dim strDestDatabasePassword As String
Dim oDestDB As DAO.Database
strSourceDatabasePathNName = ExtractDatabaseDetails.GetDatabasePath(sDatabaseID) & "\" & ExtractDatabaseDetails.GetDatabaseName(sDatabaseID)
strSourceDatabasePassword = GetDatabasePassword(sDatabaseID)
strDestDatabasePathNName = ExtractDatabaseDetails.GetDatabasePath(gsPnPDatabaseID) & "\" & ExtractDatabaseDetails.GetDatabaseName(gsPnPDatabaseID)
strDestDatabasePassword = GetDatabasePassword(gsPnPDatabaseID)
Set objApp = New Access.Application
'Open current database to export the table from this opened database to destination database
objApp.OpenCurrentDatabase strSourceDatabasePathNName, , strSourceDatabasePassword
Set oDestDB = DBEngine.OpenDatabase(strDestDatabasePathNName, _
False, False, "MS Access;PWD=" & strDestDatabasePassword)
Me.Repaint
'Export the needed tables and queries
objApp.DoCmd.TransferDatabase Access.AcDataTransferType.acExport, _
"Microsoft Access", _
strDestDatabasePathNName, _
Access.AcObjectType.acTable, "" & sSourceTblNm & "", "" & sDestTblNm & "", , False
Me.Repaint
Set objApp = Nothing
ExitHandler:
DoCmd.Hourglass (False)
Exit Sub
ErrHandler:
MsgBox "Error detected, error # " & Err.Number & ", " & Err.Description, vbOKOnly, "Error"
lblStatus.Caption = Err.Description
DoCmd.Hourglass (False)
varStatus = SysCmd(acSysCmdClearStatus)
Resume ExitHandler
End Sub
I have tried with following as well
Code:
objApp.DoCmd.TransferDatabase Access.AcDataTransferType.acExport, _
"Microsoft Access", _
strDestDatabasePathNName, _
Access.AcObjectType.acTable, "" & sSourceTblNm & "", "" & sDestTblNm & "", , True
It's still prompting for the password.
Re: Problem using TransferDatabase method from Password Protected database
Any idea how to avoid password prompt ?