Try:
Public Sub testGetQryCount()
If (getQryCount("query1")) = 0 Then
MsgBox "You are missing information." & vbCrLf & _
"Please fill out the form completely.", vbCritical + vbOKOnly, _
"Cannot Continue!"
Else
'Open mail merge document
Application.FollowHyperlink "c:\letters\letter1.doc"
End If
End Sub
Public Function getQryCount(sQryName As String) As Long
On Error GoTo ErrHandler
Dim recSet As DAO.Recordset
Dim fOpenedRecSet As Boolean
Set recSet = CurrentDb().OpenRecordset("SELECT COUNT(*) " & _
"FROM " & sQryName)
If (Not (recSet.BOF And recSet.EOF)) Then
getQryCount = recSet.Fields(0).Value
Else
getQryCount = 0
End If
CleanUp:
If (fOpenedRecSet) Then
recSet.Close
fOpenedRecSet = False
End If
Set recSet = Nothing
Exit Function
ErrHandler:
MsgBox "Error in getQryCount( )." & vbCrLf & vbCrLf & _
"Error #" & Err.Number & vbCrLf & vbCrLf & Err.Description
Err.Clear
GoTo CleanUp
End Function
HTH.
Gunny
See
http://www.QBuilt.com for all your database needs.
See
http://www.Access.QBuilt.com for Microsoft Access tips.
(Please remove ZERO_SPAM from my reply E-mail address so that a message will
be forwarded to me.)
- - -
If my answer has helped you, please sign in and answer yes to the question
"Did this post answer your question?" at the bottom of the message, which
adds your question and the answers to the database of answers. Remember that
questions answered the quickest are often from those who have a history of
rewarding the contributors who have taken the time to answer questions
correctly.