472,805 Members | 2,001 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

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(tmpPartid) 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 6257
Assuming the form is not already open, you can cancel its Open event if it
has no records:

Private Sub Form_Open(Cancel As Integer)
If Me.RecordsetClone.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.net> wrote in message
news:5r********************************@4ax.com...

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(tmpPartid) 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*********@SeeSig.Invalid> wrote:
Assuming the form is not already open, you can cancel its Open event if it
has no records:

Private Sub Form_Open(Cancel As Integer)
If Me.RecordsetClone.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
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
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...
5
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,...
9
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...
13
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...
13
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...
6
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...
6
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...
6
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...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.