Results 1 to 12 of 12
  1. #1
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740

    Unanswered: set references from code ?? possible ??

    anyone know a way to check & set library references from code?

    specifically, as a DAO old-timer, i would like to auto-set a DAO 3.6 reference if not currently referenced. it's either that or learn ADO!

    thanks for your wisdom.

    izy

  2. #2
    Join Date
    Feb 2003
    Location
    Auckland, NZ
    Posts
    150
    I Know DAO is easy, and I went through the same phase but since I have learnt ADO I have never looked back. It may be a good idea to learn ADO.
    JJ Kennedy
    Double J IT Solutions
    www.doublejit.co.nz

    VB 6, VB.NET, ASP.NET, MS SQL Server, MySQL, MS Access

  3. #3
    Join Date
    Jan 2003
    Location
    Rockville, MD
    Posts
    179

    Re: set references from code ?? possible ??

    I found a way to check 'em, but was never successful at setting them.
    Code:
    Sub ShowApplicationReferences()
       Dim intRef As Integer
       If Application.References.Count = 0 Then
          Debug.Print "Application has no references"
       Else
          Debug.Print "Application has " & CStr(Application.References.Count) & " reference(s):"
          For intRef = 0 To Application.References.Count - 1
             Debug.Print Application.References(intRef + 1).Name & Chr(9) & Application.References(intRef + 1).FullPath
          Next
       End If
    End Sub

  4. #4
    Join Date
    Mar 2003
    Posts
    46
    I use the following to Add/Remove references:

    Function AddReference() As Boolean
    Dim ref As Reference, strFile As String

    On Error GoTo Error_AddReference
    strFile = "C:\Program Files\blp\api\activex\blpdatax.dll" 'Data Type Library filepath
    Set ref = References.AddFromFile(strFile)
    AddReference = True

    Exit_AddReference:
    Exit Function

    Error_AddReference:
    MsgBox Err & ": " & Err.Description
    AddReference = False
    Resume Exit_AddReference
    End Function

    Function RemoveReference() As Boolean

    Dim ref As Reference

    On Error GoTo Error_RemoveReference
    Set ref = References!BLP_DATA_CTRLLib 'Data Type Library name
    References.Remove ref
    RemoveReference = True

    Exit_RemoveReference:
    Exit Function

    Error_RemoveReference:
    MsgBox Err & ": " & Err.Description
    RemoveReference = False
    Resume Exit_RemoveReference
    End Function

    Change "C:\Program Files\blp\api\activex\blpdatax.dll" to whatever filepath your Data Type Library has and change "References!BLP_DATA_CTRLLib" to your specific Data Type Library name

    Hope it helps

    C

  5. #5
    Join Date
    Dec 2003
    Posts
    11

    Question

    Is there a way to set the references without knowing the path for the libraries?

    Trying to make a bulletproof installation(for dummies) of my db, without needing any user interaction to set the references. (when not knowing what path the user stores the lib files)

    Please help me on this one!

  6. #6
    Join Date
    Dec 2003
    Posts
    11

    Question

    Would it make conflicts if I deliver the reference files to the user, and installs them in a ex. MyApp\DLL\ folder? will this do any harm to the users other db's?

  7. #7
    Join Date
    Mar 2003
    Posts
    46
    Hi there - apologies for the delay, haven't been on the forum for a while.

    I have yet to find a dynamic method of setting references without knowing the filepath - if you find one, let me know.

    As far as whether installing the driver in a separate folder - can't see why that would create a conflict but why not try on your own machine first just to be safe?

    Regards
    C

  8. #8
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    the answer is above.

    set the library manually and you can discover the name of the library with JTRockville's routine.

    once you know the name of the library, you can use JTRockville's routine slightly modified to find the FullPath.
    along the lines of:
    if .Name = "DAO" then strFile = .FullPath

    ...and then CCC's routine to add the reference.

    i forgot to say thanks to these guys earlier.

    THANKS the combination of the two works perfectly.


    izy
    currently using SS 2008R2

  9. #9
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    ah yes - i see the flaw in my proposal!

    i have a uniform environment for all users so that if i can find .fullpath on my machine, i know .fullpath for all users. if you don't have this uniform environment, you have some more work to do.

    it still goes more or less the same way: manually reference on your machine, check the .name & .fullpath via JTR's routine (so now you know the file name from .fullpath e.g. "dao360.dll" in the case of .name = "DAO"

    now you need to trawl through the local machine to find the file "dao360.dll".

    dir() and some loops will probably do the job for you, but i'm sure some gurus out there have recursive file-search routines in VBA that they'd love to share with us.

    and then back to CCC's routine once you've found the .fullpath

    izy
    currently using SS 2008R2

  10. #10
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    dir c:\dao360.dll /s
    will find the file in DOS

    i haven't found a way for this to help the project yet ....interesting!

    izy
    currently using SS 2008R2

  11. #11
    Join Date
    Apr 2009
    Posts
    1

    Save, Update or Repair references

    1. Create a table called tblReferences with 3 fields:

    intUID / txtRefName / txtRefPath

    2. Create a button on a form called SaveUpdateFixReferences that runs the following VBA code:

    Sub SaveApplicationReferences()
    Dim intRef As Integer
    If Application.References.Count = 0 Then
    Debug.Print "Application has no references"
    Else
    For intRef = 0 To Application.References.Count - 1
    x = DLookup("txtRefName", "tblReferences", "txtRefName='" & Application.References(intRef + 1).Name & "'")
    If IsNull(x) Then CurrentDb.Execute "INSERT INTO tblReferences (txtRefName,txtRefPath) VALUES ('" & Application.References(intRef + 1).Name & "','" & Application.References(intRef + 1).FullPath & "')"
    Next
    End If
    Call RepairReferences
    End Sub




    Public Sub RepairReferences()
    On Error Resume Next
    Set rsRef = CurrentDb.OpenRecordset("tblReferences")
    Do While Not rsRef.EOF
    Access.References.Remove rsRef!txtRefName
    Access.References.AddFromFile rsRef!txtRefPath
    rsRef.MoveNext
    Loop
    End Sub


    Now if you copy a database to a new database (i.e. new version, new project etc) you take the references with you in a table and you can run the routine to add back any missing references.

    Steve

  12. #12
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    hi Steve,

    thanks anyway, but my original post is over five years old and the problem is resolved.

    following a clever suggestion from Wayne Phillips (an occasional contributor here) i switched from .addfromfile to .addfromGUID - fromGUID makes no assumptions about what is stored where on the client PC.

    Wayne's insight was to use version 0,0 as in
    References.AddFromGuid "{00062FFF-0000-0000-C000-000000000046}",0,0
    and let VBA determine the registered version on the client.

    i think i included an example here, but i'm sitting at my VB/SQLserver machine so i don't have A to check.


    izy
    currently using SS 2008R2

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •