Database Update

Randomblink

The Irreverent Reverend
Local time
Today, 10:16
Joined
Jul 23, 2001
Messages
279
Ok.

Here is the problem.
I have created a database.
I have a front-end database that is filled with Forms, Reports, Modules, and Macros.
The only tables that the front-end database has are LINKED tables to what I call the back-end database.
The back-end database ONLY has tables.
I then go one step further.
I COPY the front-end database into an invisible folder.
I name it Template.mdb.

In my front-end (and of course the Template.mdb) database I have a Custom Property called "MasterVersion".
Whenever I need to add a form or a report to the database, I do the following:
  1. Open the Template.mdb file
  2. Make my changes, such as adding a report
  3. Goto File -> Database Properties -> Tab:Custom -> MasterVersion
  4. I change the MasterVersion to a different value
  5. Then I close the database which also saves it
  6. and I am finished
    [/list=1]

    Then, in the front-end / Template database there is a Macro.
    It runs a function named: CompareVersion

    This function, if you will check out the code below, checks the MasterVersion of the Template, compares it to the MasterVersion of the currently open front-end database, and if they are different, it grabs the Template version off the server, and overwrites the currently opened database with a copy of the Template.

    This allows me, basically, to make changes to the Template database and everyone who has a copy of the front-end on their desktop will get updated with the newest version...

    So far, this has worked without a problem... It has worked AT WORK on an NT4 server setup, with Windows 98 / MS Office 97... Then when work upgraded to Windows 2000 / Office 2000 it still worked... no problems... HOWEVER...

    I recently created a database for a client... THEY are using Access 2002... They run Windows 2000 on their server with Windows 2000 on each desktop as well...

    I made changes to the code to reflect different server locations... I set everything up to work on their system JUST LIKE IT DOES AT MY JOB PLACE... BUT, whenever I open the front-end from the desktop? Access tries to open hundreds of instances of itself... It tweaks and moans... It cries about Workgroups and Exclusive Access... NOTHING WORKS!

    I am going crazy...
    Almost EVERYTHING I have learned about Access Databases, I have learned from this forum.

    I haven't had to ask a question in MONTHS...
    I 'feel' like a moron...
    SO...
    I am posting my code here...
    I am crossing my fingers...
    Praying to every god I know...
    And I am hoping that this is a simple 2000 vs. 2002 problem...

    If someone can help me...?
    I would be eternally grateful...
    Here is my code...

    Code:
    Option Compare Database
    Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
    
    Public Const ERROR_SUCCESS As Long = 0
    Public Const CSIDL_DESKTOP As Long = &H0
    Public Const CSIDL_PROGRAMS As Long = &H2
    Public Const CSIDL_STARTMENU As Long = &HB
    Public Const CSIDL_DESKTOPDIRECTORY As Long = &H10
    
    Public Const FO_COPY As Long = &H2
    Public Const FOF_SILENT As Long = &H4
    Public Const FOF_RENAMEONCOLLISION As Long = &H8
    Public Const FOF_NOCONFIRMATION As Long = &H10
    
    Public Type SHFILEOPSTRUCT
      hwnd      As Long
      wFunc      As Long
      pFrom      As String
      pTo        As String
      fFlags     As Integer
      fAborted   As Boolean
      hNameMaps  As Long
      sProgress  As String
    End Type
    
    
    Private Type BROWSEINFO
      hOwner As Long
      pidlRoot As Long
      pszDisplayName As String
      lpszTitle As String
      ulFlags As Long
      lpfn As Long
      lParam As Long
      iImage As Long
    End Type
    
    
    Private Declare Function SHBrowseForFolder Lib "shell32.dll" Alias "SHBrowseForFolderA" (lpBrowseInfo As BROWSEINFO) As Long
    Public Declare Function SHFileOperation Lib "Shell32" Alias "SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As Long
    Declare Function SHGetPathFromIDList Lib "Shell32" Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal pszPath As String) As Long
    Declare Function SHGetSpecialFolderLocation Lib "Shell32" (ByVal hwndOwner As Long, ByVal nFolder As Long, pidl As Long) As Long
    Public Declare Sub CoTaskMemFree Lib "ole32" (ByVal pv As Long)
    Private Declare Function apiShowWindow Lib "user32" Alias "ShowWindow" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
    Private Const BIF_RETURNONLYFSDIRS = &H1
    Dim appAccess As Access.Application, BlankHolder
    
    Public Function CompareVersion()
    On Error GoTo Err_CompareVersion
    
    Select Case GetMasterVersion
        Case GetCurrentVersion
        Case Else: CopySwap
    End Select
    
    Exit_CompareVersion:
        Exit Function
        
    Err_CompareVersion:
        errMessage Err
        Resume Exit_CompareVersion
    
    End Function
    
    Public Function GetMasterVersion() As String
        Dim wrkJet As Workspace
        Dim dbs As DAO.Database, cnt As Container
        Dim doc As Document, prp As Property
    
        ' Property not found error.
        Const conPropertyNotFound = 3270
        On Error GoTo GetSummary_Err
        
        Set wrkJet = CreateWorkspace("", "User", "")
        Set dbs = wrkJet.OpenDatabase("\\PW\engineering\wpdata\reports\Databases\Front_End_Databases\Template.mdb")
        Set doc = dbs.Containers("Databases")!UserDefined
            GetMasterVersion = doc.Properties("MasterVersion")
            dbs.Close
            wrkJet.Close
        Set doc = Nothing
        Set dbs = Nothing
    
    GetSummary_Bye:
        Exit Function
    
    GetSummary_Err:
        If Err = conPropertyNotFound Then
                MsgBox "There is no Master Version number assigned."
            Resume
        Else
            ' Unknown error.
            MsgBox Err.Description
            Resume GetSummary_Bye
        End If
    End Function
    
    Public Function GetCurrentVersion() As String
        Dim dbs As DAO.Database, cnt As Container, GetTemplateLocation As String
        Dim doc1 As Document, doc2 As Document, prp As Property
        
        ' Property not found error.
        Const conPropertyNotFound = 3270
        On Error GoTo GetSummary_Err
        
        Set dbs = CurrentDb
        Set cnt = dbs.Containers!Databases
        Set doc1 = cnt.Documents!UserDefined
        doc1.Properties.Refresh
        GetCurrentVersion = doc1.Properties("MasterVersion")
    
    GetSummary_Bye:
        Exit Function
    
    GetSummary_Err:
        If Err = conPropertyNotFound Then
                MsgBox "There is no Replica Version number assigned."
            Resume
        Else
            ' Unknown error.
            Resume GetSummary_Bye
        End If
    End Function
    
    Public Function CopySwap()
    Dim fs
    On Error GoTo Err_CopySwap
    
    '   Create a target that points to where the new version should go.
    '   TrgtLoc = "C:\WINNT\Profiles\" & GetNTUser & "\Desktop\ProjectStatus.mdb"
    '   Start up the COPY FUNCTION.
        Set fs = CreateObject("Scripting.FileSystemObject")
    '   Get the original Template and copy it to where new versions go. (True means to overwrite if a copy exists.)
        fs.CopyFile "\\PW\engineering\wpdata\reports\Databases\Front_End_Databases\Template.mdb", TNmLoc, True
    '   Start up the OPEN DATABASE FUNCTION.
        Set appAccess = CreateObject("Access.Application")
    '   Open the new database that was just copied from the Template.
        appAccess.OpenCurrentDatabase TNmLoc, False
    '   Close the old version of the database.
        DoCmd.Quit acQuitSaveNone
    
    Exit_CopySwap:
        Call CompareVersion
        Exit Function
    
    Err_CopySwap:
        MsgBox Err.Description
        Resume Exit_CopySwap
    
    End Function
    
    Public Sub CreateDesktopLink(sSource As String, sDestination As String)
    'working variables
    Dim sFiles As String, SHFileOp As SHFILEOPSTRUCT
    
    'terminate passed strings with a null
    sSource = sSource & Chr$(0)
    sDestination = sDestination & Chr$(0)
    
    'set up the options
    With SHFileOp
        .wFunc = FO_COPY
        .pFrom = sSource
        .pTo = sDestination
        .fFlags = FOF_SILENT Or FOF_NOCONFIRMATION
    End With
    
    'and perform the copy
    Call SHFileOperation(SHFileOp)
      
    End Sub
    
    
    Public Function GetSpecialFolder(hwnd As Long, CSIDL As Long) As String
    Dim pidl As Long, pos As Long, sPath As String
    
    'fill the pidl with the specified folder item
    If SHGetSpecialFolderLocation(hwnd, CSIDL, pidl) = ERROR_SUCCESS Then
    'initialize & get the path
        sPath = Space$(260)
        If SHGetPathFromIDList(ByVal pidl, ByVal sPath) Then
            'has a null?
            pos = InStr(sPath, Chr$(0))
            'strip it
            If pos Then
                'return folder
                GetSpecialFolder = Left$(sPath, pos - 1)
            End If
        End If
    End If
    Call CoTaskMemFree(pidl)
    End Function
    
    Public Function TNmLoc() As String
    On Error GoTo Err_TNmLoc
    
    Dim DskTp As String, DbNm As String
    DskTp = GetSpecialFolder(0&, CSIDL_DESKTOPDIRECTORY)
    DbNm = "\Midwest Customer Application.mdb"
    
    TNmLoc = DskTp & DbNm
    
    Exit_TNmLoc:
    Exit Function
    
    Err_TNmLoc:
    MsgBox Err.Description
    Resume Exit_TNmLoc
    
    End Function
    
    Public Function GetNTUser() As String
    On Error GoTo Err_GetNTUser
    'Returns the network login name
    Dim strUserName As String
    'Create a buffer
    strUserName = String(100, Chr$(0))
    'Get user name
    GetUserName strUserName, 100
    'Strip the rest of the buffer
    strUserName = Left$(strUserName, InStr(strUserName, Chr$(0)) - 1)
    GetNTUser = LCase(strUserName)
    
    Exit_GetNtUser:
    Exit Function
    
    Err_GetNTUser:
    MsgBox Err.Description
    Resume Exit_GetNtUser
    
    ' SAMPLE USAGE:
    ' Me!<insert field name here> = GetNTUser
    
    End Function

    Thank you if you can help... or even offer a suggestion for an alternative way to go... I am open to anything...

    Thank you all...
 
Brian,

Too painful to wade through all of the code (nothing personal: it's bad enough wading through my own code -- which I should be doing right now rather than goofing around here) and so I can only guess, posing some questions that may or may not point you in the right direction.

Do the users in both environments have the same permissions on the same folders?

Did you know that Windows 2000 and NT do not use the same default folder to hold user profiles? (See CopySwap.)

Have you thoroughly searched the MS KnowledgeBase using the error messages you've received?

Is "Oklahoma is OK" still printed on the car license plates there?

Regards,
Tim
 
Oklahoma is Ok

Yeah, this pitiful wreck of a bankrupt state still has that on their license plates... chuckle... Good Lord I can't wait to move 'home' to Ireland...

As for your other comments...
I didn't check the MSKnowledgeBase because the Error Messages seemed rather straight forward... They made sense in a way...

The Users do NOT have the same permissions in both environments... That is the problem...

Altho, I have recently discovered, through searching these boards... That Access 2002 has changes to the security measures inherent in it... So I am going to get a copy of 2002 for home to play around with... (I built this on a Windows 2000 / Office 2000 system and am TRYING to port it to a Windows 2000 / Access 2002 system) ugh!

Thanks for the fish anyway man...
 
Brian....you shared this code with me on another post and I've been trying to get it to work on our database. I know just enough code to be "dangerous" so a lot of things aren't readily obvious to me. I've been playing around with it for a day or so and I can't seem to get it. Can you assist with a "lite" version of the process (or rem them out) without the users, permissions etc. to make it a bit easier for me to apply to a much simpler application than you seem to be dealing with? Thanks again for the help!
Peter
 
Lite Version...

It's Sunday...
I will try to piece together a well documented/commented version by tomorrow... or even a Lite Version to help ya out... I understand it can be annoying to work with code you never read...
 
Monday...

Um, I spoke too soon.
I am going to be adjusting the code in question either tonight or tomorrow. Let me get that adjustment in place and THEN I will send you the updated code. The GetMasterVersion function is NOT working in Access 2002, so I am going to try a table based idea, I have it worked out in my head, but it isn't written yet. I will try to get a copy to you as soon as I get it working...

Later...
 
Thanks Brian.....please don't consider this any kind of emergency. Peter
 

Users who are viewing this thread

Back
Top Bottom