Running a macro from within a database

J

Jeremy

I have a query set up in Access 2003 to search a list of client names. I want
to be able to pull up some scanned images from the client file from the
query. I have figured out how to use the runapp command in a macro to do so,
however, I am unsure as to how to run the macro from within the query. Also I
would like the query to return a message box saying that there are no records
if no records exist. How can I do that?
 
M

MGFoster

Jeremy said:
I have a query set up in Access 2003 to search a list of client names. I want
to be able to pull up some scanned images from the client file from the
query. I have figured out how to use the runapp command in a macro to do so,
however, I am unsure as to how to run the macro from within the query. Also I
would like the query to return a message box saying that there are no records
if no records exist. How can I do that?

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

The query cannot open a MsgBox. You could set up a VBA routine that
opens the query, reads the file name from a column and opens the file.
There would be a separate VBA routine that opens the file.

As an example::::::

The query would look something like this:

SELECT FileName_ColumnName As ImageFile
FROM table_name
WHERE <criteria>

The VBA routine would be something like this:

Public Sub OpenImageFile(strFileName As string)

' the folder were images are stored
Const PATH = "C:\My Documents\Images\"

strFileName = PATH & strFileName

' use some sort of application to open the file

End Sub

You'd have to run the query from another VBA routine so it could pop up
a MsgBox when the query finishes. Something like this:

Private Sub cmdRunQuery()
' Use a Command Button to run the query

Const QRY = "theQueryName"

Dim db As DAO.Database, qd As DAO.QueryDef, rs As DAO.Recordset
Dim strFileName As String

Set db = CurrentDb
Set qd = db.QueryDefs(QRY)
Set rs = qd.OpenRecordset(dbForwardOnly)

Do While Not rs.EOF

' read the file name and run the file open routine
strFileName = rs!ImageFile

' Open the file image
OpenImageFile strFileName

rs.MoveNext

Loop

MsgBox "Query Finished", vbInformation

exit_:
Set rs = Nothing
Set qd = Nothing
Set db = Nothing
Exit Sub

err_:
' Set up some sort of error trap

End Sub

--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)
** Respond only to this newsgroup. I DO NOT respond to emails **

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBSZzp/IechKqOuFEgEQLGxgCgpPF08l2RB/tdY65x2qDA50TOHLQAn3mT
rw46por6SYiolWKNJ0HbBRrk
=Ufxb
-----END PGP SIGNATURE-----
 
Top