bonjour, dans la FAQ access et code VBA il y a un exemple d'application afin d'ouvrir d'une appli access une autre base Access et ouvrir un de ses formulaires.
voici le code :
dans un module :
puis on appelle la fonction :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69 Private Declare Function apiSetForegroundWindow Lib "user32" _ Alias "SetForegroundWindow" _ (ByVal hwnd As Long) _ As Long Private Declare Function apiShowWindow Lib "user32" _ Alias "ShowWindow" _ (ByVal hwnd As Long, _ ByVal nCmdShow As Long) _ As Long Private Const SW_MAXIMIZE = 3 Private Const SW_NORMAL = 1 Function fOpenRemoteForm(strMDB As String, _ strForm As String, _ Optional intView As Variant) _ As Boolean Dim objAccess As Access.Application Dim lngRet As Long On Error GoTo fOpenRemoteForm_Err If IsMissing(intView) Then intView = acViewNormal If Len(Dir(strMDB)) > 0 Then Set objAccess = New Access.Application With objAccess lngRet = apiSetForegroundWindow(.hWndAccessApp) lngRet = apiShowWindow(.hWndAccessApp, SW_MAXIMIZE) 'le premier appel à ShowWindow semble rester sans effet lngRet = apiShowWindow(.hWndAccessApp, SW_MAXIMIZE) .OpenCurrentDatabase strMDB .DoCmd.OpenForm strForm, intView Do While Len(.CurrentDb.Name) > 0 DoEvents Loop End With End If fOpenRemoteForm_Exit: On Error Resume Next objAccess.Quit Set objAccess = Nothing Exit Function fOpenRemoteForm_Err: fOpenRemoteForm = False Select Case err.Number Case 7866: 'mdb ouverte en mode exclusif MsgBox "The database you specified " & vbCrLf & strMDB & _ vbCrLf & "is currently open in exclusive mode. " & vbCrLf _ & vbCrLf & "Please reopen in shared mode and try again", _ vbExclamation + vbOKOnly, "Could not open database." Case 2102: 'ce formulaire n'existe pas MsgBox "The Form '" & strForm & _ "' doesn't exist in the Database " _ & vbCrLf & strMDB, _ vbExclamation + vbOKOnly, "Form not found" Case 7952: 'l'utilisateur a fermer la base de données fOpenRemoteForm = True Case Else: MsgBox "Error#: " & err.Number & vbCrLf & err.DESCRIPTION, _ vbCritical + vbOKOnly, "Runtime error" End Select Resume fOpenRemoteForm_Exit End Function
je teste donc ce script il lance bien une autre instance de ACCESS puis c'est vide et j'ai une erreur :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2 Call fOpenRemoteForm("chemin_de_ma_base\base.mdb", "Form_a_ouvrir")
merci d'avance pour de l'aideerreur 91 : variable objet ou avec block variable non défini
Alex
Partager