referance Microsoft Scripting Runtime

rob.low

Access Nutter
Local time
Today, 12:34
Joined
Dec 27, 2007
Messages
96
hi All

Looking for some help please.

i have the following code to get the hard drive serial number (works ok)

the problem is i have to set the references to Microsoft Scripting Runtime' which makes it hard to distribute my database.

is ther any way i can referance to it in vba?

so i can untick this in the referances ?

thanks for any help
Rob :)


Function GetDriveVolumeSerialNumber()
'You must set the reference to 'Microsoft Scripting Runtime'
Dim fs As New FileSystemObject
Dim drvDrive As Drive
Dim strPath As String

On Error GoTo ErrorDetected

strPath = Environ("SystemDrive")
Set drvDrive = fs.GetDrive(strPath)
GetDriveVolumeSerialNumber = drvDrive.SerialNumber

MsgBox (GetDriveVolumeSerialNumber)

Exit Function

ErrorDetected:

MsgBox Err.Number & " - " & Err.Description

End Function
 
surely if you set the reference, and distribute the database thats it - it will still be set on the new computer.
 
Hi gemma-the-husky
yes you are right

but the database i send out exports a module and a form in to the clients database and if they dont have the reference set it will not run.

was looking for a way without asking clients to have to set them.

thanks
rob :)
 
there must be a way

i got code from here that checks references, and relinks if they are broken -search for broken references


this is the module i got

Code:
Option Compare Database
Option Explicit

Public gbl_fields_string As String

' ******** 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
'
'  structure contains version information about a file. This
'  information is language and code page independent.
Private Type VS_FIXEDFILEINFO
    '  Contains the value 0xFEEFO4BD (szKey)
    dwSignature As Long
    '  Specifies the binary version number of this structure.
    dwStrucVersion As Long
    '  most significant 32 bits of the file's binary version number.
    dwFileVersionMS As Long
    '  least significant 32 bits of the file's binary version number.
    dwFileVersionLS As Long
    '  most significant 32 bits of the binary version number of
    ' the product with which this file was distributed
    dwProductVersionLS As Long
    '  least significant 32 bits of the binary version number of
    ' the product with which this file was distributed
    dwFileFlagsMask As Long
    '  Contains a bitmask that specifies the valid bits in dwFileFlags.
    dwProductVersionMS As Long
    '  Contains a bitmask that specifies the
    '  Boolean attributes of the file.
    dwFileFlags As Long
    '  operating system for which this file was designed.
    dwFileOS As Long
    '  general type of file.
    dwFileType As Long
    '  function of the file.
    dwFileSubtype As Long
    '  most significant 32 bits of the file's 64-bit
    ' binary creation date and time stamp.
    dwFileDateMS As Long
    '  least significant 32 bits of the file's 64-bit binary
    ' creation date and time stamp.
    dwFileDateLS As Long
End Type
 
'  Returns size of version info in Bytes
Private Declare Function apiGetFileVersionInfoSize _
    Lib "version.dll" Alias "GetFileVersionInfoSizeA" _
    (ByVal lptstrFilename As String, _
    lpdwHandle As Long) _
    As Long
 
'  Read version info into buffer
' /* Length of buffer for info *
' /* Information from GetFileVersionSize *
' /* Filename of version stamped file *
Private Declare Function apiGetFileVersionInfo Lib _
    "version.dll" Alias "GetFileVersionInfoA" _
    (ByVal lptstrFilename As String, _
    ByVal dwHandle As Long, _
    ByVal dwLen As Long, _
    lpData As Any) _
    As Long
 
'  returns selected version information from the specified
'  version-information resource.
Private Declare Function apiVerQueryValue Lib _
    "version.dll" Alias "VerQueryValueA" _
    (pBlock As Any, _
    ByVal lpSubBlock As String, _
    lplpBuffer As Long, _
    puLen As Long) _
    As Long
 
Private Declare Sub sapiCopyMem _
    Lib "kernel32" Alias "RtlMoveMemory" _
    (Destination As Any, _
    Source As Any, _
    ByVal Length As Long)

Function fGetProductVersion(strExeFullPath As String) As String
'
'  Returns the build number for Office exes
'
' Sample usage (Access 2000)
'      ?fGetProductVersion(SysCmd(acSysCmdAccessDir) & "Frontpg.exe") '
'  Product                  Pre-SR1              Post-SR1
'  ---------------------------------------------------------
'  MSAccess.exe        9.0.0.2719           9.0.0.3822
'  WinWord.exe        9.0.0.2717            9.0.0.3822
'  Excel.exe              9.0.0.2719           9.0.0.3822
'  FrontPg.exe          4.0.2.2717            4.0.2.3821
'  Outlook.exe          9.0.0.2416            9.0.0.2416
'  PowerPnt.exe        9.0.0.2716            9.0.0.3821
'  WinProj.exe          8.0.98.407            Don't have it, sorry.
'
On Error GoTo ErrHandler
Dim lngSize As Long
Dim lngRet As Long
Dim pBlock() As Byte
Dim lpfi As VS_FIXEDFILEINFO
Dim lppBlock As Long
 
    '  GetFileVersionInfo requires us to get the size
    '  of the file version information first, this info is in the format
    '  of VS_FIXEDFILEINFO struct
    lngSize = apiGetFileVersionInfoSize( _
                        strExeFullPath, _
                        lngRet)
 
    '  If the OS can obtain version info, then proceed on
    If lngSize Then
        '  the info in pBlock is always in Unicode format
        ReDim pBlock(lngSize)
        lngRet = apiGetFileVersionInfo(strExeFullPath, 0, _
                                lngSize, pBlock(0))
        If Not lngRet = 0 Then
            '  the same pointer to pBlock can be passed to VerQueryValue
            lngRet = apiVerQueryValue(pBlock(0), _
                                "\", lppBlock, lngSize)
 
            '  fill the VS_FIXEDFILEINFO struct with bytes from pBlock
            '  VerQueryValue fills lngSize with the length of the block.
            Call sapiCopyMem(lpfi, ByVal lppBlock, lngSize)
            '  build the version info strings
            With lpfi
                fGetProductVersion = HIWord(.dwFileVersionMS) & "." & _
                                                LOWord(.dwFileVersionMS) & "." & _
                                                HIWord(.dwFileVersionLS) & "." & _
                                                LOWord(.dwFileVersionLS)
            End With
        End If
    End If
 
exithere:
    Erase pBlock
    Exit Function
ErrHandler:
    Resume exithere
End Function
 
Private Function LOWord(dw As Long) As Integer
'    retrieves the low-order word from the given 32-bit value.
    If dw And &H8000& Then
        LOWord = dw Or &HFFFF0000
    Else
        LOWord = dw And &HFFFF&
    End If
End Function
 
Private Function HIWord(dw As Long) As Integer
'    retrieves the high-order word from the given 32-bit value.
  HIWord = (dw And &HFFFF0000) \ &H10000
End Function
' ******** Code End *********
 
Sub ListReferences()
Dim refCurr As Reference
Dim strg As String
  
  strg = ""
  For Each refCurr In Application.References
    strg = strg & vbCrLf & refCurr.Name & ": " & refCurr.FullPath & _
      " (" & fGetProductVersion(refCurr.FullPath) & ")"
    Next

    Call MsgBox(strg, vbInformation)
End Sub



Sub DetectRefs(tname As String)
    Dim loRef As Access.Reference
    Dim intCount As Integer
    Dim intX As Integer
    Dim blnBroke As Boolean
    Dim strPath As String
    Dim x As Long
    Dim strg As String
    Dim kinds(2) As String
    Dim sqlstrg As String
    
    kinds(0) = "TypeLib"
    kinds(1) = "Project"
    
    
    On Error Resume Next

    'Count the number of references in the database
    intCount = Access.References.Count
  
    'Loop through each reference in the database
    'and determine if the reference is broken.
    For intX = intCount To 1 Step -1
      Set loRef = Access.References(intX)
      
        With loRef
          sqlstrg = "INSERT INTO " & tname & "  " & _
            "(refname, refpath, refmajor, refminor, refbuiltin, reftype, refversion, refbroken) " & _
            "SELECT" & _
            Chr(34) & .Name & Chr(34) & " , " & _
            Chr(34) & .FullPath & Chr(34) & " , " & _
            Chr(34) & .Major & Chr(34) & " , " & _
            Chr(34) & .Minor & Chr(34) & " , " & _
            .BuiltIn & " , " & _
            Chr(34) & kinds(.Kind) & Chr(34) & " , " & _
            Chr(34) & fGetProductVersion(.FullPath) & Chr(34) & " , " & _
            .IsBroken
       
       
            On Error GoTo fail
'            MsgBox (sqlstrg)
            currentdb.Execute sqlstrg, dbFailOnError
            GoTo refloop
       
fail:
            Call MsgBox("Error inserting reference: " & vbCrLf & vbCrLf & _
                "Error: " & Err & "   Desc: " & Err.Description)
            Resume Next
       End With
refloop:
    Next
    
  Set loRef = Nothing
    MsgBox ("References Table Updated")
End Sub


Sub Fix_References(showme As Boolean)
    
    Dim loRef As Access.Reference
    Dim intCount As Integer
    Dim intX As Integer
    Dim blnBroke As Boolean
    Dim NoFile As Boolean
    
    Dim strPath As String
    
    Dim fixstrg As String
    Dim okstrg As String
    Dim fixcount As Long

    On Error Resume Next

    'Count the number of references in the database
    intCount = Access.References.Count
  
    'Loop through each reference in the database
    'and determine if the reference is broken.
    'If it is broken, remove the Reference and add it back.
    fixcount = 0
    fixstrg = ""
    okstrg = ""
    
    For intX = intCount To 1 Step -1
      Set loRef = Access.References(intX)
      With loRef
        NoFile = Len(Dir(.FullPath)) = 0
        blnBroke = .IsBroken
        
        If blnBroke = True Or NoFile = True Or Err <> 0 Then
            
            MsgBox (loRef.Name & "  is broken, or the dll does not exist. " & vbCrLf & "Full Path: " & .FullPath)
            strPath = .FullPath
            On Error GoTo fail
            Access.References.Remove loRef
            Access.References.AddFromFile strPath
            
            fixstrg = fixstrg & loRef.Name & vbCrLf
            fixcount = fixcount + 1
            
        Else
            okstrg = okstrg & loRef.Name & vbCrLf
        End If
        GoTo refloop
        
fail:
        Call MsgBox("Error rebuilding reference: " & vbCrLf & "Name: " & loRef.Name & vbCrLf & _
            "Path: " & loRef.FullPath)
        Resume Next
      End With
refloop:
    Next
    
  Set loRef = Nothing
  If fixcount > 0 Then
    Call MsgBox(fixcount & " References rebuilt. " & vbCrLf & vbCrLf & _
        fixstrg)
  Else
    Call MsgBox("All References OK. No changes required. " & vbCrLf & vbCrLf & okstrg)
  End If
  
  ' Call a hidden SysCmd to automatically compile/save all modules.
'  Call SysCmd(504, 16483)
End Sub
 
thanks for reply
still cant sort it out loll

any help ?
 
thanks for reply
still cant sort it out loll

any help ?

I might be missing something but why can't you just use late binding?

Dim fs
Dim drvDrive
Dim strPath As String


Set fs = CreateObject("Scripting.FileSystemObject")
strPath = Environ("SystemDrive")
Set drvDrive = fs.GetDrive(strPath)
GetDriveVolumeSerialNumber = drvDrive.SerialNumber

MsgBox (GetDriveVolumeSerialNumber)
 
Hi jibbajabba

That worked thank you :)

just wondering could i do this for the dao3.6 object library ?

if so could you post an example of the code to do this.

thanks for help

Rob :)
 
Hi Rob,

Take a look at this old bit of Excel kb...

http://support.microsoft.com/kb/152400

It shows you how to go about opening a recordset in an mdb from Excel.

Of course, you can ship an access database without a reference to dao - I don't know why you would though! the code to create a recordset would simply be...

Dim db As Object
Dim rs As Object
Set db = Application.CurrentDb
Set rs = db.OpenRecordset("someSQL")​

Hope this helps

JJ.

Oh, one last... not referencing an object at compile time (late binding) means that you lose the ability to use all the constants defined in the object's type library - so instead of 'just' using dbForwardOnly, dbOpenDynaSet etc. you would need to declare these constants yourself

[GLOBAL] CONST dbForwardOnly = 101

You can find out what value a Constant represents by looking in the object Browser (press f2) in a module.
 
Last edited:
Hi there
when i add the code it works ok but as soon as i untick the referance to dao3.6 it errors

still cant get my head round this loll

thanks for help andy other ideas are welcomed .
Rob. :)
 
Hi there
when i add the code it works ok but as soon as i untick the referance to dao3.6 it errors

still cant get my head round this loll

thanks for help andy other ideas are welcomed .
Rob. :)

Are we talking about a brand new database here?

If not, is there any other code in the database? As you would need to remove all declarations of DAO objects and try again.

If you still have problems, try creating a fresh database and see what happens when you try to remove the dao reference in that file.
 

Users who are viewing this thread

Back
Top Bottom