473,735 Members | 8,735 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

counting records in open form after filter, trapping for empty recordsets


Hello,

I have built a serch form for users to edit records. I only want them
to pull up the record they need, and I want to check for nulls. There
should not be dupes becasue the underlying tables are indexed. So the
user will pull up either one record or none. Here is my problem:

I pass the form name through a tmpvariable and ther other search
parameters through unbound fields on an unbound form--this works fine
unless the form opens to a null recordset--I want to trap for that. I
am currenlty oepning the form using a where clause in the OpenForm
action--relevant code is below:
MAKES SURE USER ENTERS A SEARCH TERM
If IsNull(tmpParti d) Then
MsgBox "You must enter an enrollment number to search for."
Exit Sub
End If

TMPFORMNAME IS MY HOLDING VARIABLE FOR THE FROM NAME
Dim strlinkcriteria As String
strlinkcriteria = "[PartID]=" & Me![tmpPartid] & ""
docname = tmpformname
DoCmd.OpenForm docname, , , strlinkcriteria , acFormEdit

'WANT TO TEST FOR NULL RECORDSETS HERE--i TRIED CREATING A RECORDSET
CLONE, THAT DIDN'T WORK FOR ME--I DON'T KNOW WHY. HOW CAN I EITHER
CREATE A RECORDSETCLONE AND COUNT THE RECORDS OR FIND ANOTHER WAY TO
COUNT THE RECORDS AND SEND THE USER BACK TO THE SEARCH SCREEN. i
WOULD LIKE TO COUNT THE RECORDS IN THE CURRENT OPEN FORM--SO THIS CODE
CAN APPLY TO WHATEVER FORM THE USER NEEDS TO EDIT???

OR ANY BETTER WAY I HAVE OVERLLOKED?

"If search produces no records then

MsgBox "There is no record with the ParticipantID you entered. Please
re-enter the ParticipantID"
Exit Sub
Else

I HAVE CODE THAT OPENS FORM TO THE DESIRED RECORD HERE
SNIPPED

THANKS
BOB
Feb 13 '06 #1
2 6337
Assuming the form is not already open, you can cancel its Open event if it
has no records:

Private Sub Form_Open(Cance l As Integer)
If Me.RecordsetClo ne.RecordCount = 0 Then
Cancel = True
MsgBox "No matches."
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.

<al*****@cox.ne t> wrote in message
news:5r******** *************** *********@4ax.c om...

Hello,

I have built a serch form for users to edit records. I only want them
to pull up the record they need, and I want to check for nulls. There
should not be dupes becasue the underlying tables are indexed. So the
user will pull up either one record or none. Here is my problem:

I pass the form name through a tmpvariable and ther other search
parameters through unbound fields on an unbound form--this works fine
unless the form opens to a null recordset--I want to trap for that. I
am currenlty oepning the form using a where clause in the OpenForm
action--relevant code is below:
MAKES SURE USER ENTERS A SEARCH TERM
If IsNull(tmpParti d) Then
MsgBox "You must enter an enrollment number to search for."
Exit Sub
End If

TMPFORMNAME IS MY HOLDING VARIABLE FOR THE FROM NAME
Dim strlinkcriteria As String
strlinkcriteria = "[PartID]=" & Me![tmpPartid] & ""
docname = tmpformname
DoCmd.OpenForm docname, , , strlinkcriteria , acFormEdit

'WANT TO TEST FOR NULL RECORDSETS HERE--i TRIED CREATING A RECORDSET
CLONE, THAT DIDN'T WORK FOR ME--I DON'T KNOW WHY. HOW CAN I EITHER
CREATE A RECORDSETCLONE AND COUNT THE RECORDS OR FIND ANOTHER WAY TO
COUNT THE RECORDS AND SEND THE USER BACK TO THE SEARCH SCREEN. i
WOULD LIKE TO COUNT THE RECORDS IN THE CURRENT OPEN FORM--SO THIS CODE
CAN APPLY TO WHATEVER FORM THE USER NEEDS TO EDIT???

OR ANY BETTER WAY I HAVE OVERLLOKED?

"If search produces no records then

MsgBox "There is no record with the ParticipantID you entered. Please
re-enter the ParticipantID"
Exit Sub
Else

I HAVE CODE THAT OPENS FORM TO THE DESIRED RECORD HERE
SNIPPED

THANKS
BOB

Feb 14 '06 #2
Thank you--knewe it was simple!

bob
On Tue, 14 Feb 2006 10:13:01 +0800, "Allen Browne"
<Al*********@Se eSig.Invalid> wrote:
Assuming the form is not already open, you can cancel its Open event if it
has no records:

Private Sub Form_Open(Cance l As Integer)
If Me.RecordsetClo ne.RecordCount = 0 Then
Cancel = True
MsgBox "No matches."
End If
End Sub


Feb 14 '06 #3

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

Similar topics

5
5038
by: hpi | last post by:
Hello, I have a table : Batch It contains fields batchnummer : Number (Long Integer) datum : Date/Time status : Number (Long Integer) nr_records : Number (Long Integer)
6
2505
by: Robin S. | last post by:
**Eric and Salad - thank you both for the polite kick in the butt. I hope I've done a better job of explaining myself below. I am trying to produce a form to add products to a table (new products). Tables: tblCategoryDetails CategoryID SpecID
5
1551
by: -:= Cactus | last post by:
Hi! I've made a form for dataentry in a simple table. However when there are records in that table and I open the form it only displays the new (blank) record. The total number of records is 1, despite more records already being entered in the table. If I add a new record it is saved in the table and the total count of records is indeed increased by one. I can than scroll to the two records but it is not possible to scroll through the...
9
4805
by: Sandy | last post by:
Hi all, I have a form to list records (frmListIssue) which I call from different other forms. My wish is to display a message when the form is called and empty; no records to display. I want to use OpenArgs because sometimes I don't want an empty form and sometime I don't. I tried everything, but until now without success. I hope that someone can help me out here. This is an example how I call the form:
13
3170
by: Regnab | last post by:
The problem I'm having is the rsa.RecordCount always returns a '1' when I know there should be about 1600 records returned. I read somewhere that one should use '.MoveLast' before recordcount but that returns ar error 'Invalid Operation'. And when I do the bottom loop, the counter happily clicks over the right number of times. Me no understand... I've got the following code (this is just a simplified example - I want to use the...
13
3433
by: kev | last post by:
Hi all, I have created a database for equipments. I have a form to register the equipment meaning filling in all the particulars (ID, serial, type, location etc). I have two buttons at the end of the form which is submit and cancel. After i have clicked submit, the information is stored directly into my corresponding database table. My problem here is i need to retrieve back the information submitted to display all the data that the...
6
2773
by: gerbski | last post by:
Hi all, I am relatively new to ADO, but up to now I got things working the way I wanted. But now I've run into somethng really annoying. I am working in MS Access. I am using an Access frontend separately from a backend. The tables from the backend database are linked in the frontend database. In the frontend there is a Form with a listbox in it. The listbox rowsource is a query that selects all the records from a (linked)
6
9427
by: Dave | last post by:
On my form I have combo boxes. These combo boxes, after updating them, populate respective listboxes that are located below the combo boxes on the same form. I am trying to use a "generate report" button located on my form to print all of the list box values (that have been updated via selection from combo boxes) from the form to the report. I've tried using a macro with the code: Macro Name: cmdGenerateReport : On Click Action:...
6
2357
jinalpatel
by: jinalpatel | last post by:
I am using following code for searching records. 'Purpose: Build up the criteria string form the non-blank search boxes, and apply to the form's Filter. 'Notes: 1. We tack " AND " on the end of each condition so you can easily add more search boxes; _ we remove the trailing " AND " at the end. Dim strWhere As String 'The criteria string. Dim lngLen As...
0
8962
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8785
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
9251
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9200
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8201
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4559
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4822
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3273
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2739
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.