473,396 Members | 1,942 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Closing a form automatically if no records

Hi all,
Im opening a bound form, targetForm from other forms, but want close it if
there's no records in it. Would be good if I could do this from within the
targetForm, since I open it from various activities.

I have already tried to close it from the onOpen event of targetForm but
without success.
Any advice welcome.

Thanks,

Gerry Abbott,


Feb 7 '06 #1
6 8647
Try something like this:

Private Sub Form_Open(Cancel As Integer)
If Me.RecordsetClone.RecordCount = 0 Then
Cancel = True
MsgBox "Nobody home."
End If
End Sub

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Gerry Abbott" <pl****@ask.ie> wrote in message
news:ox******************@news.indigo.ie...
Hi all,
Im opening a bound form, targetForm from other forms, but want close it if
there's no records in it. Would be good if I could do this from within the
targetForm, since I open it from various activities.

I have already tried to close it from the onOpen event of targetForm but
without success.
Any advice welcome.

Feb 7 '06 #2
On Tue, 7 Feb 2006 12:38:47 -0000, "Gerry Abbott" <pl****@ask.ie> wrote:
Hi all,
Im opening a bound form, targetForm from other forms, but want close it if
there's no records in it. Would be good if I could do this from within the
targetForm, since I open it from various activities.

I have already tried to close it from the onOpen event of targetForm but
without success.
Any advice welcome.

Thanks,

Gerry Abbott,


Private Sub Form_Open(Cancel As Integer)

With Me.RecordsetClone
If .RecordCount = 0 Then
Beep
MsgBox "There are no records to view", vbInformation + vbOKOnly
Cancel = True
End If
End With

End Sub
Wayne Gillespie
Gosford NSW Australia
Feb 7 '06 #3
Two ways AFAIK,

A cancel on form open.
But: When you are opening your form with code you will have to trap error 2501

Or:
Private Sub Form_Load()
If Me.RecordsetClone.RecordCount = 0 Then
MsgBox "No records.."
DoCmd.Close
End If
End Sub
Arno R

"Gerry Abbott" <pl****@ask.ie> schreef in bericht news:ox******************@news.indigo.ie...
Hi all,
Im opening a bound form, targetForm from other forms, but want close it if
there's no records in it. Would be good if I could do this from within the
targetForm, since I open it from various activities.

I have already tried to close it from the onOpen event of targetForm but
without success.
Any advice welcome.

Thanks,

Gerry Abbott,



Feb 7 '06 #4
Arno R <ar***********@tiscali.nl> wrote:
: Private Sub Form_Load()
: If Me.RecordsetClone.RecordCount = 0 Then
^^^^^
why isn't Recordset itself good enough here?
--thelma
: MsgBox "No records.."
: DoCmd.Close
: End If
: End Sub

: Arno R
Feb 7 '06 #5

"Thelma Lubkin" <th****@alpha2.csd.uwm.edu> schreef in bericht news:ds**********@uwm.edu...
Arno R <ar***********@tiscali.nl> wrote:
: Private Sub Form_Load()
: If Me.RecordsetClone.RecordCount = 0 Then
^^^^^
why isn't Recordset itself good enough here?
--thelma
: MsgBox "No records.."
: DoCmd.Close
: End If
: End Sub

: Arno R


I guess one an use Me.Recordset also, but I see this property is only available with Access2k or better.
I am used to use Recordsetclone, but it was in the Access 2.0 days that I learned about that ...

Arno R
Feb 7 '06 #6
Thelma Lubkin <th****@alpha2.csd.uwm.edu> wrote in
news:ds**********@uwm.edu:
Arno R <ar***********@tiscali.nl> wrote:
: Private Sub Form_Load()
: If Me.RecordsetClone.RecordCount = 0 Then
^^^^^
why isn't Recordset itself good enough here?
--thelma
: MsgBox "No records.."
: DoCmd.Close
: End If
: End Sub


For one, Me.Recordset did not exist until Access 2000.

Secondly, it's not the same thing as the RecordsetClone.

Try it and see if there's a difference. My bet is that there *is* a
difference, but not necessarily for this particular task.

You might also want to check out Michael Kaplan's article on
Recordset vs. RecordsetClone:

http://trigeminal.com/usenet/usenet022.asp?1033

Personally, I don't see any utility in the Recordset object of a
form unless you are assigning a recordset to the form in code,
rather than using the form's Recordsource to define the content of
the form.

--
David W. Fenton http://www.dfenton.com/
usenet at dfenton dot com http://www.dfenton.com/DFA/
Feb 7 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

22
by: Theo | last post by:
Question for the group The authentication system for the site Im working on seems to function properly and all is good. A session keeps track of everything and a cookie is used to accept or deny...
1
by: pdemarais | last post by:
What is the differance between refreshing a form and closing/reopening a form. When I refresh data in a form and click on a record in a list box the information that shows is from the 1st record....
10
by: Charles Law | last post by:
For some reason, when I click the X to close my MDI parent form, the action appears to be re-directed to one of the MDI child forms, and the parent remains open. I am then unable to close the...
5
by: Oenone | last post by:
I have a VB.NET form which I'm displaying modally using the ShowDialog() method. Within the form is a Cancel button, and I've set this button into the Form's CancelButton property so that...
4
by: tlyczko | last post by:
I have been looking on the NGs and I found this code to show if a subform has no records. I have this code in the MAIN form OnClose event: Private Sub btnClose_Click() '4/16/06 new code that...
3
by: Iain | last post by:
How do I get a form to automatically refresh once (not continually using a timer). The scenario I have uses a parent table and a child table. (thanks to mmcarthy for indicating better termenology...
14
by: =?Utf-8?B?UHVjY2E=?= | last post by:
Hi, I'm using VS2005 and .net 2.0. I'm creating an application that has 3 forms. I want allow users to move forward and backward with the forms and retain the data users have entered. I thought...
19
by: zacks | last post by:
I have a .NET 2.0 MDI application where the child form has a Tab Control. Each of the Tab in the Tab Control has a Validating event to handle what it should do when the user changes tabs. But...
13
by: eighthman11 | last post by:
using Access 2003 and sql server version 8.0 Hey everyone. Created a text box where the user types in an Inventory number and it takes them to that inventory number on the contimuous form. The...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.