Open file

Status
Niet open voor verdere reacties.

bertje123

Gebruiker
Lid geworden
13 nov 2007
Berichten
57
Hoi

Ik weet hoe je een file opent via vba access -->
Application.FollowHyperlink ("de directory")

Maar nu wil ik als het bestand openstaat, dat hij gewoon dat venster naar voor brengt.

if weet al wanneer hij locked is of niet, dus wanneer hij locked zou zijn, dan zou ik gewoon de file moeten krijgen die al openstaat en niet een tweede keer openen.

Iemand een idee?

Groeten !
 
Met FollowHyperlink neemt windows het van Access over en heb je er geen zeggenschap meer over. Wat je zou kunnen doen is het Access window minimaliseren na een klik op de hyperlink. Dan komt het laatste geopende programma naar voren.

HTH:D
 
He, is een optie, maar ik heb soms 10 vensters openstaan en denk niet dat dit een optie is :).
Er moet toch iets bestaan dat hij ziet dat de file locked is en dat hij dan gaat zoeken waar het al open staat en dan gewoon naar voor brengt :/

Bleh! ^^ :D
 
Dat is hogere wiskunde.
Je moet dan in je lopende processen kunnen zien welk document geopend is. Ik weet niet of dat kan. Je kan wel zien welk progamma geopend is en welke dll's die nodig heeft. Van die geopende processen zou je dan de applicatie over kunnen (getobject) nemen en op die manier te weten komen welk document geopend is...

Als je die code gevonden hebt wil je die hier dan posten?

Succes met zoeken.
 
Laatst bewerkt:
Je kunt met een programma als Winbatch wel de namen van geopende vensters uitlezen, en zelfs in een variabele in Access teruglezen. Of dat onder hogere wiskunde valt, is een andere vraag ;)
Of dat in een Access forum moet worden behandeld?
 
Met het lezen van de window captions ben je er niet als daar de naam van het geopende document niet instaat.
Daar heb je winbatch niet voor nodig. dat kan ook met een windows api.
Bijvoorbeeld met de code die ik gebruik om te onderzoeken of een Access applicatie al eens is geopend
Code:
Option Compare Database
Option Explicit

'RunCode
'    =winCheckMultipleInstances(False)
'******************** Code Start ********************
' Module mdlCheckMultipleInstances
' © Graham Mandeno, Alpha Solutions, Auckland, NZ
' graham@alpha.co.nz
' This code may be used and distributed freely on the condition
' that the above credit is included unchanged.

Private Const cMaxBuffer = 255
Private Const GW_CHILD = 5
Private Const GW_HWNDNEXT = 2
 
Private Declare Function apiGetClassName Lib "user32" Alias "GetClassNameA" (ByVal hWnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Private Declare Function apiGetDesktopWindow Lib "user32" Alias "GetDesktopWindow" () As Long
Private Declare Function apiGetWindow Lib "user32" Alias "GetWindow" (ByVal hWnd As Long, ByVal wCmd As Long) As Long
Private Declare Function apiGetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hWnd As Long, ByVal lpString As String, ByVal aint As Long) As Long
Private Declare Function apiSetActiveWindow Lib "user32" Alias "SetActiveWindow" (ByVal hWnd As Long) As Long
Private Declare Function apiIsIconic Lib "user32" Alias "IsIconic" (ByVal hWnd As Long) As Long
Private Declare Function apiShowWindowAsync Lib "user32" Alias "ShowWindowAsync" (ByVal hWnd As Long, ByVal nCmdShow As Long) As Long
 
Private Const SW_SHOW = 5
Private Const SW_RESTORE = 9

Public Function winGetClassName(hWnd As Long) As String
    Dim sBuffer As String, iLen As Integer
    sBuffer = String$(cMaxBuffer - 1, 0)
    iLen = apiGetClassName(hWnd, sBuffer, cMaxBuffer)
    If iLen > 0 Then
        winGetClassName = VBA.Left$(sBuffer, iLen)
    End If
End Function
 
Public Function winGetTitle(hWnd As Long) As String
    Dim sBuffer As String, iLen As Integer
    sBuffer = String$(cMaxBuffer - 1, 0)
    iLen = apiGetWindowText(hWnd, sBuffer, cMaxBuffer)
    If iLen > 0 Then
        winGetTitle = VBA.Left$(sBuffer, iLen)
    End If
End Function
 
Public Function winGetHWndDB(Optional hWndApp As Long) As Long
    Dim hWnd As Long
    winGetHWndDB = 0
    If hWndApp <> 0 Then
        If winGetClassName(hWndApp) <> "OMain" Then Exit Function
    End If
    hWnd = winGetHWndMDI(hWndApp)
    If hWnd = 0 Then Exit Function
    hWnd = apiGetWindow(hWnd, GW_CHILD)
    Do Until hWnd = 0
        If winGetClassName(hWnd) = "ODb" Then
            winGetHWndDB = hWnd
            Exit Do
        End If
        hWnd = apiGetWindow(hWnd, GW_HWNDNEXT)
    Loop
End Function
 
Public Function winGetHWndMDI(Optional hWndApp As Long) As Long
    Dim hWnd As Long
    winGetHWndMDI = 0
    If hWndApp = 0 Then hWndApp = Application.hWndAccessApp
    hWnd = apiGetWindow(hWndApp, GW_CHILD)
    Do Until hWnd = 0
        If winGetClassName(hWnd) = "MDIClient" Then
            winGetHWndMDI = hWnd
            Exit Do
        End If
    hWnd = apiGetWindow(hWnd, GW_HWNDNEXT)
    Loop
End Function
 
Public Function winCheckMultipleInstances(Optional fConfirm As Boolean = True) As Boolean
    Dim fSwitch As Boolean, sMyCaption As String
    Dim hWndApp As Long, hWndDb As Long
    On Error GoTo ProcErr
    sMyCaption = winGetTitle(winGetHWndDB())
    hWndApp = apiGetWindow(apiGetDesktopWindow(), GW_CHILD)
    Do Until hWndApp = 0
        If hWndApp <> Application.hWndAccessApp Then
            hWndDb = winGetHWndDB(hWndApp)
            If hWndDb <> 0 Then
                If sMyCaption = winGetTitle(hWndDb) Then Exit Do
            End If
        End If
        hWndApp = apiGetWindow(hWndApp, GW_HWNDNEXT)
    Loop
    If hWndApp = 0 Then Exit Function
    If fConfirm Then
        If MsgBox(sMyCaption & " is al geopend" & vbCrLf _
        & "Wilt u deze database nog eens openen?" & vbCrLf, _
        vbYesNo Or vbQuestion Or vbDefaultButton2, GetAppTitle) = vbYes Then Exit Function
    End If
    apiSetActiveWindow hWndApp
    If apiIsIconic(hWndApp) Then
        apiShowWindowAsync hWndApp, SW_RESTORE
    Else
        apiShowWindowAsync hWndApp, SW_SHOW
    End If
    Application.Quit
ProcEnd:
    Exit Function
ProcErr:
    MsgBox Err.Description
    Resume ProcEnd
End Function
Enjoy!
 
Status
Niet open voor verdere reacties.
Terug
Bovenaan Onderaan