Don't Open Form if NoData

Haytham

Registered User.
Local time
Today, 13:00
Joined
Jun 27, 2001
Messages
162
Hi All...
In a switchboard, I have 2 UnBound Fields: DateFrom and DateTo by which it opens a form in a specific dates required.
The form to be opened is not based on a table or query, but through a select statement. So, I can't use DCount Fuction not to open a form if NoData is there.
Is there any way to do so...
Thanks in advance:mad:
 
Private Sub Form_Open(Cancel As Integer)


With CodeContextObject
If (.RecordsetClone.RecordCount = 0) Then
DoCmd.Close
Beep
MsgBox "There are no invoices recorded for this period.Please check the dates you have entered.", vbOKOnly, "No Records"

End If
End With


End Sub
 
Rich...
Your code is very Rich... I struggled a lot to do so, but failed.
Very very thankful :)
 
What happened when you tried to run it? You did replace "CodeContextObject " with the name of your own object, right?
 
Try...
Code:
Private Sub Form_Open(Cancel As Integer)
        If Me.RecordsetClone.RecordCount = 0 Then
                DoCmd.Close acForm, Me.Name
                MsgBox "There are zero records in the data source!", vbInformation, "No Records Found"
        End If
End Sub
HTH
 
I keep seeing this "RecordsetClone.Recordset" in postings. Is this in reference to the file or form name..or am I missing something
 
When in doubt...ask Access!

If you were to select the "RecordsetClone" piece of the code and press the F1 key you would get this...

You can use the RecordsetClone property to refer to a form's Recordset object specified by the form's RecordSource property.

...and a whole lot more info.

HTH
 

Users who are viewing this thread

Back
Top Bottom