Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Detecting Vista

2 views
Skip to first unread message

PC User

unread,
Nov 27, 2007, 3:28:19 PM11/27/07
to
I've seen a number of codes to detect the current operating system,
but they haven't been updated to detect vista. One of the more
commonly referred codes at The Access Web http://www.mvps.org/access/api/api0055.htm
; however, it doesn't detect vista. Does anyone have a code to detect
the current windows version that includes Vista?

Thanks,
PC

Douglas J. Steele

unread,
Nov 27, 2007, 3:48:37 PM11/27/07
to
Vista should be

.dwMajorVersion = 5 And _
.dwMinorVersion = 2 Then

(I think the code from "The Access Web" identifies it as ""Windows .NET
Server ")

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)


"PC User" <pc_...@softhome.net> wrote in message
news:99788a82-963e-4a1f...@a35g2000prf.googlegroups.com...

Ron Hinds

unread,
Nov 27, 2007, 6:48:19 PM11/27/07
to
Are you sure about that? I thought it was

.dwMajorVersion = 6 And _
.dwMinorVersion = 0 Then

"Douglas J. Steele" <NOSPAM_djsteele@NOSPAM_canada.com> wrote in message
news:uRKMkbTM...@TK2MSFTNGP04.phx.gbl...

Douglas J. Steele

unread,
Nov 27, 2007, 7:06:15 PM11/27/07
to
You're absolutely right. 5 & 2 is Windows 2003. Don't know what I was
thinking of.

Thanks for the assist. (Sorry for the misinformation, PC User!)

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele

(no private e-mails, please)


"Ron Hinds" <bi...@microsoft.com> wrote in message
news:%23i8Qt%23UMIH...@TK2MSFTNGP04.phx.gbl...

PC User

unread,
Nov 27, 2007, 8:45:13 PM11/27/07
to
It sounds like I need to add some code the referenced procedure.
Would it be something like this?
If .dwPlatformId = VER_PLATFORM_WIN32_WINDOWS And _

.dwMajorVersion = 6 And _
.dwMinorVersion = 0 Then
strOut = "Windows Vista (Version " & _
.dwMajorVersion & "." & .dwMinorVersion & _
") Build " & .dwBuildNumber
If (Len(.szCSDVersion)) Then
strOut = strOut & " (" & _
fTrimNull(.szCSDVersion) & ")"
End If
End If

Thanks,
PC

Douglas J. Steele

unread,
Nov 28, 2007, 8:34:37 AM11/28/07
to
Exactly.

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)


"PC User" <pc_...@softhome.net> wrote in message

news:2e31f29e-8165-49c2...@e25g2000prg.googlegroups.com...

Dirk Goldgar

unread,
Nov 28, 2007, 11:46:27 AM11/28/07
to
"PC User" <pc_...@softhome.net> wrote in message
news:2e31f29e-8165-49c2...@e25g2000prg.googlegroups.com...


That's good, except that I've found that the code concerned with
.szCSDVersion (whatever that is) isn't right. I modified the code as
follows:

'----- start of modified code (summarized) -----

Dim strCSDVersion As String

' ...

With osvi

strCSDVersion = fTrimNull(.szCSDVersion)
If (Len(strCSDVersion)) Then
strCSDVersion = " (" & strCSDVersion & ")"
End If

' ...

' Vista
If .dwPlatformId = VER_PLATFORM_WIN32_NT And _


.dwMajorVersion = 6 And _
.dwMinorVersion = 0 Then
strOut = "Windows Vista (Version " & _
.dwMajorVersion & "." & .dwMinorVersion & _

") Build " & .dwBuildNumber & strCSDVersion
End If

'----- end of modified code (summarized) -----

I made similar changes (concatenating strCSDVersion into strOut) in the
other OS versions to which it applies.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)

PC User

unread,
Nov 28, 2007, 7:01:58 PM11/28/07
to
I tried using this function on a field on a form and activating it by
the On Load form event using Me.txtWindowsVersion = fOSName() and it
doesn't work. What am I doing wrong? See code below.

Code
'=========================
Option Compare Database

' ******** Code Start ********
'This code was originally written by Dev Ashish.
'It is not to be altered or distributed,
'except as part of an application.
'You are free to use it in any application,
'provided the copyright notice is left unchanged.
'
'Code Courtesy of
'Dev Ashish
'

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

Private Declare Function apiGetVersionEx Lib "kernel32" _
Alias "GetVersionExA" _
(lpVersionInformation As Any) _
As Long

Private Const VER_PLATFORM_WIN32_WINDOWS = 1
Private Const VER_PLATFORM_WIN32_NT = 2

'==================================================

Function fOSName() As String
Dim osvi As OSVERSIONINFO
Dim strOut As String
Dim strCSDVersion As String

osvi.dwOSVersionInfoSize = Len(osvi)
If CBool(apiGetVersionEx(osvi)) Then
With osvi

strCSDVersion = fTrimNull(.szCSDVersion)
' Win 2000


If .dwPlatformId = VER_PLATFORM_WIN32_NT And _

.dwMajorVersion = 5 Then
strOut = "Windows 2000 (Version " & _


.dwMajorVersion & "." & .dwMinorVersion & _
") Build " & .dwBuildNumber
If (Len(.szCSDVersion)) Then
strOut = strOut & " (" & _
fTrimNull(.szCSDVersion) & ")"
End If
End If

' XP


If .dwPlatformId = VER_PLATFORM_WIN32_NT And _

.dwMajorVersion = 5 And _

.dwMinorVersion = 1 Then
strOut = "Windows XP (Version " & _


.dwMajorVersion & "." & .dwMinorVersion & _
") Build " & .dwBuildNumber
If (Len(.szCSDVersion)) Then
strOut = strOut & " (" & _
fTrimNull(.szCSDVersion) & ")"
End If
End If

' .Net Server


If .dwPlatformId = VER_PLATFORM_WIN32_NT And _

.dwMajorVersion = 5 And _
.dwMinorVersion = 2 Then

strOut = "Windows .NET Server (Version " & _


.dwMajorVersion & "." & .dwMinorVersion & _
") Build " & .dwBuildNumber
If (Len(.szCSDVersion)) Then
strOut = strOut & " (" & _
fTrimNull(.szCSDVersion) & ")"
End If
End If

' Win ME
If (.dwMajorVersion = 4 And _
(.dwPlatformId = VER_PLATFORM_WIN32_WINDOWS And _
.dwMinorVersion = 90)) Then
strOut = "Windows Millenium"
End If
' Win 98
If (.dwMajorVersion = 4 And _
(.dwPlatformId = VER_PLATFORM_WIN32_WINDOWS And _
.dwMinorVersion = 10)) Then
strOut = "Windows 98"
End If
' Win 95
If (.dwPlatformId = VER_PLATFORM_WIN32_WINDOWS And _
.dwMinorVersion = 0) Then
strOut = "Windows 95"
End If
' Win NT
If (.dwPlatformId = VER_PLATFORM_WIN32_NT And _
.dwMajorVersion <= 4) Then
strOut = "Windows NT " & _


.dwMajorVersion & "." & .dwMinorVersion & _

" Build " & .dwBuildNumber
If (Len(.szCSDVersion)) Then
strOut = strOut & " (" & _
fTrimNull(.szCSDVersion) & ")"
End If

'*************************************************************************


' Vista
If .dwPlatformId = VER_PLATFORM_WIN32_NT And _
.dwMajorVersion = 6 And _
.dwMinorVersion = 0 Then
strOut = "Windows Vista (Version " & _
.dwMajorVersion & "." & .dwMinorVersion & _
") Build " & .dwBuildNumber & strCSDVersion

If (Len(strCSDVersion)) Then
strCSDVersion = " (" & strCSDVersion & ")"
End If

End If
'*************************************************************************
End If
End With
End If
fOSName = strOut
End Function

'==================================================

Private Function fTrimNull(strIn As String) As String
Dim intPos As Integer
intPos = InStr(1, strIn, vbNullChar)
If intPos Then
fTrimNull = Mid$(strIn, 1, intPos - 1)
Else
fTrimNull = strIn
End If
End Function
' ********** Code End **********
'=========================


Thanks,
PC

Douglas J. Steele

unread,
Nov 28, 2007, 7:17:15 PM11/28/07
to
What does "doesn't work" mean?

Do you get an error message? If so, what's the message? If you don't get an
error message, what symptom are you experiencing?

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no private e-mails, please)

"PC User" <pc_...@softhome.net> wrote in message

news:b5805db6-391c-4b2a...@i29g2000prf.googlegroups.com...

PC User

unread,
Nov 28, 2007, 8:30:22 PM11/28/07
to
I also tried this on the On Open form event and there is no response.
Either way there is no error message or information displayed in the
unbound field intended to display the Windows Version. Is there
another way to use this function to try it?

Thanks,
PC

Douglas J. Steele

unread,
Nov 29, 2007, 8:07:41 AM11/29/07
to
Open the immediate window (Ctrl-G), type

?fOSName

and hit Enter.

The response should be written right underneath:

?fOSName
Windows XP (Version 5.1) Build 2600 (Service Pack 2)


--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele

(no e-mails, please!)


"PC User" <pc_...@softhome.net> wrote in message

news:3fb288f2-01a8-4fc1...@s12g2000prg.googlegroups.com...

PC User

unread,
Nov 29, 2007, 10:17:23 AM11/29/07
to

Ok Doug,
I deleted all the unused code for my project, since
the only two operating systems at our company is Windows XP and
Windows Vista. So now the code works in the immediate window. I
don't know what the problem with the portion of code that I removed,
but now the code below does work. Thanks Doug.

?fOSName
Windows Vista (Version 6.0) Build 6000

Function fOSName() As String


Dim osvi As OSVERSIONINFO
Dim strOut As String
Dim strCSDVersion As String

osvi.dwOSVersionInfoSize = Len(osvi)
If CBool(apiGetVersionEx(osvi)) Then
With osvi

strCSDVersion = fTrimNull(.szCSDVersion)
' XP
<*************************************************************


If .dwPlatformId = VER_PLATFORM_WIN32_NT And _
.dwMajorVersion = 5 And _
.dwMinorVersion = 1 Then
strOut = "Windows XP (Version " & _
.dwMajorVersion & "." & .dwMinorVersion & _
") Build " & .dwBuildNumber
If (Len(.szCSDVersion)) Then
strOut = strOut & " (" & _
fTrimNull(.szCSDVersion) & ")"
End If
End If

' Vista
<*************************************************************


If .dwPlatformId = VER_PLATFORM_WIN32_NT And _
.dwMajorVersion = 6 And _
.dwMinorVersion = 0 Then
strOut = "Windows Vista (Version " & _
.dwMajorVersion & "." & .dwMinorVersion & _
") Build " & .dwBuildNumber & strCSDVersion
If (Len(strCSDVersion)) Then
strCSDVersion = " (" & strCSDVersion & ")"
End If
End If

End With


End If
fOSName = strOut
End Function

PC User

unread,
Nov 29, 2007, 10:51:50 AM11/29/07
to
My purpose in trying to detect the current OS is to change the links
to the reference libraries that differ between Access 2000 and Access
2007. When I think of it, maybe I should be detecting which version
of Access that I'm using instead of which OS? Is there a way to do
this and use the results for Access to programmically change
references?

Thanks,
PC

Ron Hinds

unread,
Nov 29, 2007, 12:20:23 PM11/29/07
to
"PC User" <pc_...@softhome.net> wrote in message
news:28e3047e-b869-484b...@d21g2000prf.googlegroups.com...

Application.Version will return a string with the version number (e.g. 11.0
for Access 2003).


Douglas J. Steele

unread,
Nov 29, 2007, 12:54:46 PM11/29/07
to
The OS shouldn't matter: usually it's only the version of Access that
matters unless you're using OS-dependent ActiveX controls.

But what references are you trying to change? It's seldom necessary (nor a
good idea). Use late binding as much as you can. If you are going to change
references, make sure you read what MichKa's got at
http://www.trigeminal.com/usenet/usenet026.asp

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)


"PC User" <pc_...@softhome.net> wrote in message

news:28e3047e-b869-484b...@d21g2000prf.googlegroups.com...

PC User

unread,
Nov 29, 2007, 9:55:01 PM11/29/07
to
Doug,

I have Vista and Office 2007 on my computer and our temp worker
has XP and Office 2000 on his. We share the backend of a database,
but when ever I upgrade the programming in the database I give him a
copy. There are references the database uses that it has trouble
finding when I give him a copy of the database (in compatible mode)
that I've upgraded while using Office 2007. References that the
database seems to have trouble locating are as follows.
=======================================
Office 2000 references
Microsoft Excel 9.0 Object Library
Microsoft Common Dialog Control 6.0 (SP)
Microsoft Windows Common Control 6.0 (SP)


Office 2007 references
Microsoft Excel 12.0 Object Library
=======================================
Everytime I give him an upgrade, I have to reset the references.
Since I'm not a professional programmer, I'm developing the database
as I'm also being productive on my main projects. The database when
completed, is intended to automate a number of parts of my project and
will help to expedite reports that have previously involved manualling
filling in the forms made on MS Word documents. Switching between MS
Office versions and resetting the references is a bit of a nuisance
and I'd like to automate it. Hopefully, my company will upgrade the
remaining computers to Vista and Office 2007 and I won't have to do
this.

Thanks,
PC

Tony Toews [MVP]

unread,
Nov 30, 2007, 1:31:24 AM11/30/07
to
PC User <pc_...@softhome.net> wrote:

>Microsoft Excel 9.0 Object Library

Use late binding. Late binding means you can safely remove the
reference and only have an error when the app executes lines of code
in question. Rather than erroring out while starting up the app and
not allowing the users in the app at all. Or when hitting a mid, left
or trim function call.

You'll want to install the reference if you are programming or
debugging and want to use the object intellisense while in the VBA
editor. Then,. once your app is running smoothly, remove the
reference and setup the late binding statements.

Sample code:
' Declare an object variable to hold the object
' reference. Dim as Object causes late binding.
Dim objWordDoc As Object
Set objWordDoc = CreateObject(" Word.Document")

For more information including additional text and some detailed links
see the "Late Binding in Microsoft Access" page at
http://www.granite.ab.ca/access/latebinding.htm

>Microsoft Common Dialog Control 6.0 (SP)
>Microsoft Windows Common Control 6.0 (SP)

Use API calls for these.

How do you get rid of troublesome ActiveX Controls/references?
http://www.granite.ab.ca/access/referencetroubles.htm
Now these look like ugly code. However it's mostly a matter of
dropping in the wrapper API functions into a module and calling them.

>Office 2007 references
>Microsoft Excel 12.0 Object Library

Late binding again.

Tony
--
Tony Toews, Microsoft Access MVP
Please respond only in the newsgroups so that others can
read the entire thread of messages.
Microsoft Access Links, Hints, Tips & Accounting Systems at
http://www.granite.ab.ca/accsmstr.htm
Tony's Microsoft Access Blog - http://msmvps.com/blogs/access/

PC User

unread,
Nov 30, 2007, 2:00:54 PM11/30/07
to
Thanks for the link. It will take some study on my part.

PC

PC User

unread,
Dec 2, 2007, 11:54:20 PM12/2/07
to
Ok. I did find code to determine the version of MS Access, but again I
need help to detect Version 2007 and put the info into a textbox
instead of a word document. Here's the code. Can someone help me on
this?

Code
================================
Public Function OfficeDir(OffVer As String) As String
On Error GoTo ErrorTrap

Dim objWord As Object

Set objWord = CreateObject("Word.Application")

Select Case OffVer
Case "acc97"
OfficeDir = objWord.System.PrivateProfileString("", _
"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\8.0", _
"BinDirPath") & "\msaccess.exe"
'Debug.Print OfficeDir
Case "acc2k"
OfficeDir = objWord.System.PrivateProfileString("", _
"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\9.0\Access
\InstallRoot", _
"Path") & "msaccess.exe"
Debug.Print OfficeDir
Case "accxp"
OfficeDir = objWord.System.PrivateProfileString("", _
"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\10.0\Access
\InstallRoot", _
"Path") & "msaccess.exe"
Debug.Print OfficeDir
Case Else
End Select

objWord.quit
Set objWord = Nothing

Exit Function
ErrorTrap:

objWord.Close
Set objWord = Nothing
MsgBox "Error " & Err & ". " & Err.Description & ".", vbCritical
Exit Function

End Function
================================

Thanks,
PC

DABO

unread,
Dec 3, 2007, 7:00:11 AM12/3/07
to
c'est pas la peine de m'envoyer des message je répondrais bon aller bye bye
good bye a+a++++

"PC User" <pc_...@softhome.net> a écrit dans le message de groupe de
discussion :
b224877a-0b04-4a9e...@s12g2000prg.googlegroups.com...

PC User

unread,
Dec 3, 2007, 1:09:11 PM12/3/07
to
I finally figured it out. I'm posting this for other who can use it.
=====================================
Public Function AccessVersion()
Dim objRetVal As Integer
Set objAccess = CreateObject("Access.Application")
objRetVal = objAccess.SysCmd(acSysCmdAccessVer)

Select Case objRetVal
Case "8.0"
AccessVersion = "97"
Case "9.0"
AccessVersion = "2000"
Case "10.0"
AccessVersion = "2002"
Case "11.0"
AccessVersion = "2003"
Case "12.0"
AccessVersion = "2007"
End Select
Set objAccess = Nothing

End Function
=====================================

0 new messages