Blade Hunter
Well-known Member
- Joined
- Mar 13, 2008
- Messages
- 3,147
Dimensionalise this at a global level:
Global Const RepVer As String = "1.1"
At the Workbook level:
In a module:
I hope this helps someone. I am using it on an app that people are already using but I am continuing development of. This way even if someone copies it to their local rather than running from the host file, it will update whenever I push out a new version .
All you do is change your global RepVer to a new version and update the version on the database to match it and voila
Cheers
Dan
Global Const RepVer As String = "1.1"
At the Workbook level:
Code:
Private Sub Workbook_Open()
Call CheckVer
If CurrentRepVer <> RepVer Then
If MsgBox("Latest version on server = " & CurrentRepVer & " This version = " & RepVer & Chr(13) & Chr(13) & "You need to either copy the latest version from: ""<LOCATION file of>"" or set up a shortcut to this file. Would you like me to copy the latest version for you?" & _
Chr(13) & Chr(13) & "It is highly recommended that you set up a shortcut to this file rather than saving a local copy to ensure you always use the latest version.", vbYesNo, "Version conflict detected") = vbYes Then
Call CopyNewVersion
End If
End If
End Sub
In a module:
Code:
Sub CopyNewVersion()
Dim OldWorkBookDIR As String
Dim OldWorkBook As String
Dim NewWorkBookDIR As String
Dim NewWorkBook As String
NewWorkBookDIR = "dir of new workbook"
NewWorkBook = "name of new workbook"
OldWorkBookDIR = ThisWorkbook.Path & "\"
OldWorkBook = Left(ThisWorkbook.Name, Len(ThisWorkbook.Name) - 4) & "_OLD_" & Format(Now(), "YYYYMMDD") & ".xls" 'Formats to backup the old one including the date.
ThisWorkbook.SaveAs (OldWorkBook)
FileCopy NewWorkBookDIR & NewWorkBook, OldWorkBookDIR & NewWorkBook
Workbooks.Open OldWorkBookDIR & NewWorkBook
Workbooks(OldWorkBook).Activate
ActiveWorkbook.Close False
End Sub
Code:
Sub CheckVer()
Dim Conn As New ADODB.Connection
Dim RS As New ADODB.Recordset
Dim Cmd As New ADODB.Command
Dim sqlText As String
Dim Row As Long
Dim Findex As Long
Call Get_User
Conn.Open "PROVIDER=MSDAORA.Oracle;DATA SOURCE=;" & DBSource & _
"USER ID=" & DatabaseUserName & ";PASSWORD=" & DatabasePassword
Cmd.ActiveConnection = Conn
Cmd.CommandType = adCmdText
sqlText = "SQL Code to retrieve version from the database<SQLCODE the there stored have you that database from number Version a retrieve to>"
Cmd.CommandText = sqlText
Set RS = Cmd.Execute
Do While Not RS.EOF
Row = Row + 1
For Findex = 0 To RS.Fields.Count - 1
CurrentRepVer = RS.Fields(Findex).Value
Next Findex
RS.MoveNext
Loop
End Sub
I hope this helps someone. I am using it on an app that people are already using but I am continuing development of. This way even if someone copies it to their local rather than running from the host file, it will update whenever I push out a new version .
All you do is change your global RepVer to a new version and update the version on the database to match it and voila
Cheers
Dan
Last edited: