mdb running in two different Versions of Access

Posted on 2011-03-08
Medium Priority
Last Modified: 2012-08-13
I need to determine which operating system is running to determine which file-path to use to determine an executable.  Since Win7 file location differs from the WinXp version what is the best way to code for this situation.

My current code has a Private Const that holds the file path for the executable.  How and where do I place code that will determine if the filepath for the Win7 exists and if not look for the alternate for XP version.


Win 7 version:

Private Const mc_VIDATAX_VB_APP As String = _
   "C:\Program Files (x86)\Boeing\FTCS Apps\ViDataX\ViDataX.exe"  'ViDataX Application

Win XP version:

Private Const mc_VIDATAX_VB_APP As String = _
    "C:\Program Files\Boeing\FTCS Apps\ViDataX\ViDataX.exe"

Open in new window

Question by:Karen Schaefer

Expert Comment

ID: 35073494
Those are the same path for all intensive purposes.. it it is an install that is your issue I would edit the installation to put it in program files rather than x86 would be far easier...

your only difference is 32 bit vs 64 bit file structure.  

Author Comment

by:Karen Schaefer
ID: 35073537
Yes, I need code that will determine if the X86 directory/file exists and if so chose the first const and if not choose the 2nd Const - which will need to be renamed.

I was thinking something like.

if Find Directory A = true then
 use Const1
end if

Expert Comment

ID: 35073558
You may use the following code to determine the folder location:

Public Enum SpecialFolderIDs
  sfidDESKTOP = &H0                  ' Desktop
  sfidNTERNET = &H1                  ' Internet Explorer (icon on desktop)
  sfidPROGRAMS = &H2                 ' Start Menu\Programs
  sfidCONTROLS = &H3                 ' My Computer\Control Panel
  sfidPRINTERS = &H4                 ' My Computer\Printers
  sfidPERSONAL = &H5                 ' My Documents
  sfidFAVORITES = &H6                ' \Favorites
  sfidSTARTUP = &H7                  ' StartMenu\Programs\Startup
  sfidRECENT = &H8                   ' \Recent
  sfidSENDTO = &H9                   ' \SendTo
  sfidBITBUCKET = &HA                ' \Recycle Bin
  sfidSTARTMENU = &HB                ' \StartMenu
  sfidDESKTOPDIRECTORY = &H10        ' name>\Desktop
  sfidDRIVERS = &H11                 ' My Computer
  sfidNETWORK = &H12                 ' Network Neighborhood
  sfidNETHOOD = &H13                 ' \nethood
  sfidFONTS = &H14                   ' windows\fonts
  sfidTEMPLATES = &H15
  sfidCOMMON_STARTMENU = &H16        ' All Users\StartMenu
  sfidCOMMON_PROGRAMS = &H17         ' AllUsers\Programs
  sfidCOMMON_STARTUP = &H18          ' AllUsers\Startup
  sfidCOMMON_DESKTOPDIRECTORY = &H19 ' AllUsers\Desktop
  sfidAPPDATA = &H1A                 ' name>\Application Data
  sfidPRINTHOOD = &H1B               ' name>\PrintHood
  sfidLOCAL_APPDATA = &H1C           ' name>\Local Settings\Applicaiton Data (non roaming)
  sfidALTSTARTUP = &H1D              ' non localizedstartup
  sfidCOMMON_ALTSTARTUP = &H1E       ' non localizedCommon startup
  sfidCOOKIES = &H21
  sfidHISTORY = &H22
  sfidCOMMON_APPDATA = &H23          ' AllUsers\Application Data
  sfidWINDOWS = &H24                 ' GetWindowsDirectory()
  sfidSYSTEM = &H25                  ' GetSystemDirectory()
  sfidPROGRAM_FILES = &H26           ' C:\Program Files
  sfidMYPICTURES = &H27              ' C:\Program Files\My Pictures
  sfidPROFILE = &H28                 ' USERPROFILE
  sfidSYSTEMX86 = &H29               ' x86 system directory on RISC
  sfidPROGRAM_FILESX86 = &H2A        ' x86 C:\Program Files on RISC
  sfidPROGRAM_FILES_COMMON = &H2B    ' C:\Program Files\Common
  sfidPROGRAM_FILES_COMMONX86 = &H2C ' x86 Program Files\Common on RISC
  sfidCOMMON_TEMPLATES = &H2D        ' All Users\Templates
  sfidCOMMON_DOCUMENTS = &H2E        ' All Users\Documents
  sfidCOMMON_ADMINTOOLS = &H2F       ' All Users\Start Menu\Programs\Administrative Tools
  sfidADMINTOOLS = &H30              ' \Start Menu\Programs\Administrative Tools
  sfidProgramFiles = &H10000
  sfidCommonFiles = &H10001
End Enum

Private Declare Function SHGetSpecialFolderLocation Lib "shell32.dll" (ByVal hwndOwner As Long, ByVal nFolder As Long, pidl As ITEMIDLIST) As Long
Private Declare Function SHGetPathFromIDList Lib "shell32.dll" Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal pszPath As String) As Long

Public Function GetSpecialFolder(CSIDL As SpecialFolderIDs) As String

  Dim lResult As Long
  Dim sPath As String
  lResult = SHGetSpecialFolderLocation(100, CSIDL, IDL)
  If lResult = 0 Then
    sPath = Space$(512)
    lResult = SHGetPathFromIDList(ByVal IDL.mkid.cb, ByVal sPath)
    GetSpecialFolder = Left$(sPath, InStr(sPath, Chr$(0)) - 1)
  End If
End Function
Get 10% Off Your First Squarespace Website

Ready to showcase your work, publish content or promote your business online? With Squarespace’s award-winning templates and 24/7 customer service, getting started is simple. Head to Squarespace.com and use offer code ‘EXPERTS’ to get 10% off your first purchase.


Expert Comment

ID: 35073576
Or :

>> Yes, I need code that will determine if the X86 directory/file exists

Declare Function PathFileExists Lib "shlwapi.dll" Alias "PathFileExistsA" (ByVal pszPath As String) As Long
LVL 17

Expert Comment

by:Barry Cunney
ID: 35073587
Have given sample code with possible solution
Private Sub HandleEXEPath_Click()
Select Case getVersion
    Case "Windows 7"
        ' Path for exe on Windows 7
    Case "Windows XP"
        ' Path for exe on Windows XP
    Case Else
        ' Some other operating system
End Select
End Sub

            Public Function getVersion() As String
               Dim osinfo As OSVERSIONINFO
               Dim retvalue As Integer
               osinfo.dwOSVersionInfoSize = 148
               osinfo.szCSDVersion = Space$(128)
               retvalue = GetVersionExA(osinfo)
               With osinfo
               Select Case .dwPlatformId
                Case 1
                    Select Case .dwMinorVersion
                        Case 0
                            getVersion = "Windows 95"
                        Case 10
                            getVersion = "Windows 98"
                        Case 90
                            getVersion = "Windows Millennium"
                    End Select
                Case 2
                    Select Case .dwMajorVersion
                        Case 3
                            getVersion = "Windows NT 3.51"
                        Case 4
                            getVersion = "Windows NT 4.0"
                        Case 5
                            If .dwMinorVersion = 0 Then
                                getVersion = "Windows 2000"
                                getVersion = "Windows XP"
                            End If
                        Case 6
                            If .dwMinorVersion = 0 Then
                                getVersion = "Windows Vista"
                                getVersion = "Windows 7"
                            End If
                    End Select
                Case Else
                   getVersion = "Failed"
            End Select
               End With
            End Function

' The following has to be put in a module

Public Declare Function GetVersionExA Lib "kernel32" (lpVersionInformation As OSVERSIONINFO) As Integer

               dwOSVersionInfoSize As Long
               dwMajorVersion As Long
               dwMinorVersion As Long
               dwBuildNumber As Long
               dwPlatformId As Long
               szCSDVersion As String * 128
            End Type

Open in new window


Accepted Solution

Karen Schaefer earned 0 total points
ID: 35073876
thanks for the suggestion, however, found the solution within my own code.  

Thanks for your time.
If ViDataX_File_Exists_W7 = True Then
        FP = "mc_VIDATAX_VB_APP_W7"
    ElseIf ViDataX_File_Exists_XP = True Then
        FP = "mc_VIDATAX_VB_APP_XP"
        MsgBox "Required ViDataX executable has not been installed on this machine." _
           & vbCrLf & "Contact your application support.", vbOKOnly, "ViDataX"
        Exit Function
    End If

Private Function ViDataX_File_Exists_XP() As Boolean
  On Error Resume Next
  Dim sFileName As String  'Full file name
  '-- Check that the ViDataX executable exists.
  sFileName = Dir(mc_VIDATAX_VB_APP_XP)
  If Err.Number = 0 And Len(sFileName) > 0 Then ViDataX_File_Exists_XP = True  'File exists

End Function

Open in new window


Author Closing Comment

by:Karen Schaefer
ID: 35120698

Featured Post

Get 10% Off Your First Squarespace Website

Ready to showcase your work, publish content or promote your business online? With Squarespace’s award-winning templates and 24/7 customer service, getting started is simple. Head to Squarespace.com and use offer code ‘EXPERTS’ to get 10% off your first purchase.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

What to do if a split doesn't fit? Or a bunch of invoice lines must be rounded while the sum must match a total? It takes a little, but - when done - it is extremely easy to implement.
Though there are a few manual ways to import PST files to Office 365 , third-party PST to Office 365 import tools are preferred over them due to various reasons.  Consequently, many tools or services are available for the same. Here, we pick the to…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
The Relationships Diagram is a good way to get an overall view of what a database is keeping track of. It is also where relationships are defined. A relationship specifies how two tables connect to each other. As you build tables in Microsoft Ac…

619 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question