R
Riccardo
Hello, i want to set some references in a library (library.accdb) that i'm
going to use in a main program (main.accdb). The code for doing it it's in a
sub written in the library. Here it is
--------------------------------------
Private Sub Aggiorna_Percorso_Libreria(ByVal nome As String, ByVal percorso
As String)
On Error GoTo Errore
Dim i As Byte
For i = 1 To CodeProject.Application.References.Count
If CodeProject.Application.References(i).Name = nome Then
If CodeProject.Application.References(i).FullPath = percorso
Then Exit Sub
CodeProject.Application.References.Remove
CodeProject.Application.References(i)
Exit For
End If
If CodeProject.Application.References(i).Name = percorso Then
CodeProject.Application.References.Remove
CodeProject.Application.References(i)
End If
Next i
If VBA.Dir(percorso) = "" Then MsgBox "Libreria mancante al percorso: "
& percorso & VBA.Chr(10) & "L'applicazione verra' chiusa", vbCritical,
"Errore critico": DoCmd.Quit ' Notare il VBA.Chr(10) e Dir. Sfruttato nel
caso una libreria non sia collegata
CodeProject.Application.References.AddFromFile percorso
Exit Sub
Errore:
MsgBox "Errore durante la registrazione della libreria: " & percorso,
vbCritical, "Errore critico"
DoCmd.Quit
End Sub
---------------------------------------------
This code runs properly if i use it directly from the library or in any
other program, the problem is that if i call that sub from my main.accdb the
references are set for the main.accdb and not in the library.accdb
Example, if i call the sub in this way:
Aggiorna_Percorso_Librerie("library.accdb", "C:\library.accdb")
References before sub call:
Main.accdb
- vba
- dao
- ecc...
library.accdb
- vba
- dao
- ecc...
References after sub call:
main.accdb
- vba
- dao
- library.accdb
- ecc..
library.accdb
- vba
- dao
- ecc...
I don't understand why the reference is not set in the correct project file.
Thanks for any help.
going to use in a main program (main.accdb). The code for doing it it's in a
sub written in the library. Here it is
--------------------------------------
Private Sub Aggiorna_Percorso_Libreria(ByVal nome As String, ByVal percorso
As String)
On Error GoTo Errore
Dim i As Byte
For i = 1 To CodeProject.Application.References.Count
If CodeProject.Application.References(i).Name = nome Then
If CodeProject.Application.References(i).FullPath = percorso
Then Exit Sub
CodeProject.Application.References.Remove
CodeProject.Application.References(i)
Exit For
End If
If CodeProject.Application.References(i).Name = percorso Then
CodeProject.Application.References.Remove
CodeProject.Application.References(i)
End If
Next i
If VBA.Dir(percorso) = "" Then MsgBox "Libreria mancante al percorso: "
& percorso & VBA.Chr(10) & "L'applicazione verra' chiusa", vbCritical,
"Errore critico": DoCmd.Quit ' Notare il VBA.Chr(10) e Dir. Sfruttato nel
caso una libreria non sia collegata
CodeProject.Application.References.AddFromFile percorso
Exit Sub
Errore:
MsgBox "Errore durante la registrazione della libreria: " & percorso,
vbCritical, "Errore critico"
DoCmd.Quit
End Sub
---------------------------------------------
This code runs properly if i use it directly from the library or in any
other program, the problem is that if i call that sub from my main.accdb the
references are set for the main.accdb and not in the library.accdb
Example, if i call the sub in this way:
Aggiorna_Percorso_Librerie("library.accdb", "C:\library.accdb")
References before sub call:
Main.accdb
- vba
- dao
- ecc...
library.accdb
- vba
- dao
- ecc...
References after sub call:
main.accdb
- vba
- dao
- library.accdb
- ecc..
library.accdb
- vba
- dao
- ecc...
I don't understand why the reference is not set in the correct project file.
Thanks for any help.