Supply Password via VB

D

Diogo

Need some help with the fllowing code:
I use it for a aplication to connect to a server and inspect if the version
on the server is grater than the one in the local host.
I does this by comparing a number in VersionRef table in both the aplication
on the server and the local one. This works fine if the aplication on the
server and on the localhost aren't passowrd protected.
Is there a way for me to suplly the passwords (same on both) via VB to the
aplication on the server and the aplication on the local machine.

Code:

Option Compare Database

Private Sub Form_Load()

Dim rst As DAO.Recordset
Dim BEPath As String
Dim ServerFile As String
Dim ServerVersion As Integer
Dim LocalFile As String
Dim LocalVersion As Integer


' find location of files (see note about assumptions below)

BEPath = Mid(CurrentDb.TableDefs("Tabela FsL antiga").Connect, 11)
ServerFile = Left(BEPath, Len(BEPath) - 34) & "Registo documentos
Workflow_fe.mdb" '34 is specific to this app’s backend MyApp_be.mdb
LocalFile = CurrentProject.Path & "\Registo documentos Workflow_fe.mdb"

' identify the version numbers of the mde files

Set rst = CurrentDb.OpenRecordset("SELECT Version FROM VersionRef IN '"
& ServerFile & "'", dbOpenSnapshot)
ServerVersion = rst!Version
rst.Close
Set rst = CurrentDb.OpenRecordset("SELECT Version FROM VersionRef IN '"
& LocalFile & "'", dbOpenSnapshot)
LocalVersion = rst!Version
rst.Close

'replace local mde if later version is found on server

If ServerVersion > LocalVersion Then
MsgBox "Existe uma nova versão desta aplicação. A sua versão vai ser
actualizada! Carrege OK e aguarde sff!", vbInformation, "AutoUpdate"
Kill LocalFile
FileCopy ServerFile, LocalFile

End If

Me.TimerInterval = 2000
Set rst = Nothing

End Sub

Private Sub Form_Timer()

Dim LocalFile As String
Dim CmdToOpen As String

'close Pilot and launch main application

Me.TimerInterval = 0
LocalFile = CurrentProject.Path & "\Registo documentos Workflow_fe.mdb"
CmdToOpen = """" & SysCmd(acSysCmdAccessDir) & "Msaccess.exe""" & " """
& LocalFile & """"
Shell CmdToOpen, vbNormalFocus
DoCmd.Quit

End Sub
 
D

Diogo

UPDATE:

Added the follwing lines to supply password, it can now check versions, but
it doesn't replace old one if new is found.


Private Sub Form_Load()

Dim rst As DAO.Recordset
Dim BEPath As String
Dim ServerFile As String
Dim ServerVersion As Integer
Dim LocalFile As String
Dim LocalVersion As Integer


' find location of files (see note about assumptions below)

BEPath = Mid(CurrentDb.TableDefs("Tabela FsL antiga").Connect, 11)
ServerFile = Left(BEPath, Len(BEPath) - 34) & "Registo documentos
Workflow_fe.mdb" '34 is specific to this app’s backend MyApp_be.mdb
LocalFile = CurrentProject.Path & "\Registo documentos Workflow_fe.mdb"

' Abrir aplicações protegidas com password

Set dbsData = DBEngine.OpenDatabase(ServerFile, False, False,
";pwd=*****")
Set dbsData = DBEngine.OpenDatabase(LocalFile, False, False, ";pwd=****")

' identify the version numbers of the mde files

Set rst = CurrentDb.OpenRecordset("SELECT Version FROM VersionRef IN '"
& ServerFile & "'", dbOpenSnapshot)
ServerVersion = rst!Version
rst.Close
Set rst = CurrentDb.OpenRecordset("SELECT Version FROM VersionRef IN '"
& LocalFile & "'", dbOpenSnapshot)
LocalVersion = rst!Version
rst.Close

'replace local mde if later version is found on server

If ServerVersion > LocalVersion Then
MsgBox "Existe uma nova versão desta aplicação. A sua versão vai ser
actualizada! Carrege OK e aguarde sff!", vbInformation, "AutoUpdate"
Kill LocalFile
FileCopy ServerFile, LocalFile

End If

Me.TimerInterval = 2000
Set rst = Nothing

End Sub
 
K

Klatuu

The problem you are having is that you are trying to delete a file that is
open:
Kill LocalFile

You can't delete or rename a file while it is open.
What you could do is write a batch (.bat) file that will copy the new
version into place and start it up, then use the Shell command to run it.

If ServerVersion > LocalVersion Then
MsgBox "Existe uma nova versão desta aplicação. A sua versão vai ser
actualizada! Carrege OK e aguarde sff!", vbInformation, "AutoUpdate"
Shell(BEPath & "\UpdateVersion.bat")
Docmd.Quit
End If
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top