Generate a Msg if Zero Records Found

hfcoverlover

New member
Local time
Today, 14:59
Joined
Jun 25, 2009
Messages
3
The following is code to open a form and records with a specific date as input by the user:
Private Sub cmdDisplayCovers_Click()
On Error GoTo Err_cmdDisplayCovers_Click

Dim stDocName As String
Dim stLinkCriteria As String


stDocName = "frmInventory"
stLinkCriteria = "[tblCovers].[Date] = [Forms]![frmCoversByDate]![txtDate]"

DoCmd.OpenForm stDocName, , , stLinkCriteria

etc. etc.

Am looking for help to generate a message to user if no records match the input and then return to the
input form. Any help appreciated. Currently, the form opens even with no records. I have searched the forum,
but many samples are way above.
Don
 
Hmm, perhaps a DLookup() or a DCount() to see if there are any records, if none open Form in Data Entry mode and if records then open to show the selected records. So, something like...


Code:
 If DCount("YourField","YourTableOrQuery","FieldFromTable='" & [FieldOnForm] & "'") > 0 Then
      DoCmd.OpenForm "frmInventory", , , "[tblCovers].[Date] = [Forms]![frmCoversByDate]![txtDate]"
 Else
      DoCmd.OpenForm "frmInventory", , , ,acFormAdd
 End if
 

Users who are viewing this thread

Back
Top Bottom