open all record file using hyperlink. (1 Viewer)

rio

Registered User.
Local time
Today, 23:04
Joined
Jun 3, 2008
Messages
124
I have a Query name tFiles Query.

FileName FilePath FilePathName
Logplace.doc c:\Database\ c:\Database\Logplace.doc
Tanplace.doc c:\Database\ c:\Database\Tanplace.doc

I used this code to open the database.

Code:
Private Sub Command3_Click()
Dim rs As Recordset
Dim x As Integer, i As Integer
Set rs = CurrentDb.OpenRecordset("tFiles Query")
x = rs.RecordCount
For i = 0 To x
OpenFile rs![FilePathName]
Next i
End Sub

i also used this module

Code:
Option Compare Database
Option Explicit

Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hWnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long

Public Function OpenFile(sFileName As String)
On Error GoTo Err_OpenFile

    OpenFile = ShellExecute(Application.hWndAccessApp, "Open", sFileName, "", "f:\", 1)

Exit_OpenFile:
    Exit Function

Err_OpenFile:
    MsgBox Err.Number & " - " & Err.description
    Resume Exit_OpenFile

End Function

when I click the button... it's open the c:\Database\Logplace.doc twice.
How to write the code to open all record just by one click????
 
Last edited:

rio

Registered User.
Local time
Today, 23:04
Joined
Jun 3, 2008
Messages
124
i got it. I change the code to :

Code:
Private Sub Command3_Click()
Dim rs As Recordset
Dim x As Integer, i As Integer
Set rs = CurrentDb.OpenRecordset("tFiles Query")

Do While Not rs.EOF
x = rs.RecordCount
If x > 0 Then
OpenFile (rs![FilePath] & rs![FileName])
End If
rs.MoveNext
Loop

End Sub
 

vbaInet

AWF VIP
Local time
Today, 16:04
Joined
Jan 22, 2010
Messages
26,374
Feels great when you do it on your own doesn't it? :)

Looks like you're now a master of DAO. Bravo! ;)
 

rio

Registered User.
Local time
Today, 23:04
Joined
Jun 3, 2008
Messages
124
thanks... I'm still in learning process.
 

vbaInet

AWF VIP
Local time
Today, 16:04
Joined
Jan 22, 2010
Messages
26,374
I'm glad, you're learning fast.

For your command button 3, I would right it like this:

Code:
Private Sub Command3_Click()
Dim rs As dao.Recordset, db as dao.recordset

set db = currentdb
Set rs = db.OpenRecordset("tFiles Query", dbopensnapshot)

Do While Not rs.EOF
     OpenFile (rs![FilePath] & rs![FileName])
     rs.MoveNext
Loop
End Sub

You don't need the IF condition because Do While Not rs.EOF is doing that already. Take note of the few amendments
 

rio

Registered User.
Local time
Today, 23:04
Joined
Jun 3, 2008
Messages
124
ok... thanks again.
 

Users who are viewing this thread

Top Bottom