Broken references, Please check my code !

  • Thread starter Javier G via AccessMonster.com
  • Start date
J

Javier G via AccessMonster.com

Hi,

I 'm just starting programming so,......... Can any body please check the
following code ( do Not laugh too much, if many mistakes)

'**** START CODE *********
The function checks & try to repair if a broken reference is found
Public Function funGUID() As Boolean
On Error GoTo Err_funGUID

Dim Ref As Reference

funGUID = True

For Each Ref In References

If Ref.IsBroken = True Then
'Broken references

MsgBox "Reference: " & vbTab & Ref.Name & vbCrLf _
& "Version: " & vbTab & Ref.Major & "." & Ref.Minor &
vbCrLf _
& "Path: " & vbTab & Ref.FullPath & vbCrLf _
& "GUID: " & vbTab & Ref.Guid, vbCritical, "Error"

References.Remove Ref

Select Case Ref.Guid

'Access 9.0 (MSACC.OLB)
Case "{4AFFC9A0-5F99-101B-AF4E-00AA003F0F07}"
References.AddFromGuid "{4AFFC9A0-5F99-
101B-AF4E-00AA003F0F07}", 9, 0 'Version

'VBA 4.0 (VBE6.DLL)
Case "{000204EF-0000-0000-C000-000000000046}"
References.AddFromGuid "{000204EF-0000-
0000-C000-000000000046}", 4, 0 'Version

'DAO 5.0 (DAO360.DLL)
Case "{00025E01-0000-0000-C000-000000000046}"
References.AddFromGuid "{00025E01-0000-
0000-C000-000000000046}", 5, 0 'Version

Case Else
MsgBox "Sorry GUID Not found", vbCritical,
"Error"
End Select


If funGUID = True Then
MsgBox "Broken reference was repaired",
vbInformation, "Ok"
End If

Else
' No Broken references
MsgBox "Name: " & vbTab & Ref.Name & vbCrLf _
& "Version: " & vbTab & Ref.Major & "." & Ref.
Minor & vbCrLf _
& "Path: " & vbTab & Ref.FullPath & vbCrLf _
& "GUID: " & vbTab & Ref.Guid, vbInformation,
"References"

End If

Next Ref


If funGUID = True Then
MsgBox "Now there are Not broken references", vbInformation, "Ok"
Else
MsgBox "The program could Not repair the broken reference",
vbCritical, "Error"
End If


Exit_funGUID:
Exit Function

Err_funGUID:
'MsgBox Err.Description, vbCritical, "Error :" & Err.Number
funGUID = False
Resume Next

End Function
' ******* FINNISH CODE ***********

Thank you in advance
Javier
 
D

Douglas J. Steele

When a reference is broken, you can't refer to its Name property, nor to its
FullPath property.

And what version of Access are you using? In some versions, the AddFromGuid
method only accepts one argument: the GUID.
 
J

Javier G via AccessMonster.com

Ok !! thank you for replaying

I'm using Access 2003, but can you please write down your sugested code ??
Also I would like to know which deferences are between A 2000 version ??

Thank so much
Javier

When a reference is broken, you can't refer to its Name property, nor to its
FullPath property.

And what version of Access are you using? In some versions, the AddFromGuid
method only accepts one argument: the GUID.
[quoted text clipped - 85 lines]
Thank you in advance
Javier
 
D

Douglas J. Steele

Remove the calls to .Name and .FullPath in your messagebox:

MsgBox "Reference: " & "Version: " & vbTab _
& Ref.Major & "." & Ref.Minor & vbCrLf _
& "GUID: " & vbTab & Ref.Guid, vbCritical, "Error"

The rest of the code should work, although you have to make sure you run it
at the correct time. Read what MichKa has to say at
http://www.trigeminal.com/usenet/usenet026.asp

Sorry, I don't have Access 2000 installed. And after doing some additional
research, it turns out that while the Access 97 help file doesn't list the
Major and Minor parameters, they're still there.

However, looking at your code again, I just noticed that you're trying to
use properties of the Ref object after you've deleted it. You're going to
have to store those values in variables. And since you know all 3 parameters
you're trying to pass to the AddFromGuid method, there's no reason for the
SELECT CASE construct.

I'm also not sure that the For Each Ref In References is a good idea. Since
you may be deleting Reference objects, you may run into problems. Try
looping through all the references backwards from the end

Public Function funGUID() As Boolean
On Error Resume Next

Dim Ref As Reference
Dim booStatus As Boolean
Dim intLoop As Integer
Dim lngMajor As Long
Dim lngMinor As Long
Dim strGUID as String

booStatus = True

For intLoop = References.Count To 1 Step -1
Set Ref = References(intLoop)
If Ref.IsBroken = True Then
'Broken reference

MsgBox "Reference: " & "Version: " & vbTab _
& Ref.Major & "." & Ref.Minor & vbCrLf _
& "GUID: " & vbTab & Ref.Guid, vbCritical, "Error"

strGUID = Ref.GUID
lngMajor = Ref.Major
lngMinor = Ref.Minor

References.Remove Ref

References.AddFromGuid strGUID, lngMajor, lngMinor

booStatus = booStatus Or (Err.Number = 0)

Else
' No Broken references
MsgBox "Name: " & vbTab & Ref.Name & vbCrLf _
& "Version: " & vbTab & Ref.Major & "." & Ref.Minor & vbCrLf _
& "Path: " & vbTab & Ref.FullPath & vbCrLf _
& "GUID: " & vbTab & Ref.Guid, vbInformation, "References"
End If

Next intLoop

funGUID = booStatus

End Function

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Javier G via AccessMonster.com said:
Ok !! thank you for replaying

I'm using Access 2003, but can you please write down your sugested code ??
Also I would like to know which deferences are between A 2000 version ??

Thank so much
Javier

When a reference is broken, you can't refer to its Name property, nor to
its
FullPath property.

And what version of Access are you using? In some versions, the
AddFromGuid
method only accepts one argument: the GUID.
[quoted text clipped - 85 lines]
Thank you in advance
Javier
 
J

Javier G via AccessMonster.com

Dear Douglas thank you it is marvelous !!

Only few questions:

1- Which is the best way to reproduce a broken reference error ?? ,I want to
try this routine, without damaging my computer. (Maybe with a useless
reference).

2- What happen if a application (with your routine included), is loaded in a
new PC without one of my references ?

3- Can you re-confirm if is a better idea to deleted the broken reference
before trying to repair? (I mean References.Remove Ref )

4- Can you explain a lit more “make sure you run it at the correct time”
What Do you mean ? Such code it must be located in the first even, of the
application ?? or What do you mean ?

5- Is your routing working in Access 2000 , A2002 and A2003 ??


Thank you again, so much you helped me a lot !
Javier
 
D

Douglas J. Steele

Javier G via AccessMonster.com said:
Dear Douglas thank you it is marvelous !!

Only few questions:

1- Which is the best way to reproduce a broken reference error ?? ,I want
to
try this routine, without damaging my computer. (Maybe with a useless
reference).

Do you have 2 computers available for testing? Add a reference to something
that only exists on one of the two computers, and test on the other one.
2- What happen if a application (with your routine included), is loaded in
a
new PC without one of my references ?

If what it's trying to load using AddFromGUID doesn't exist, you'll get an
error.
3- Can you re-confirm if is a better idea to deleted the broken reference
before trying to repair? (I mean References.Remove Ref )

You have no choice: you can't add two references to the same GUID
4- Can you explain a lit more “make sure you run it at the correct time”
What Do you mean ? Such code it must be located in the first even, of the
application ?? or What do you mean ?

Did you read MichKa's article? That should explain it.
5- Is your routing working in Access 2000 , A2002 and A2003 ??

Should work in all versions.
 
G

Guest

It won't work in an MDE.

Although you could write a macro to do something similar.

(david)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top