Avatar of MikeDTE
MikeDTEFlag for United Kingdom of Great Britain and Northern Ireland

asked on 

Access: opening form with filter

I have a form that is called from a parent form.

The parent form shows booking for an event and the child form shows the payments made for the currently selected booking.

The child form fJDWEventPay Record Source is table tJDWPayments

The key field is jdwp_BookingRef.  This is an unique reference that matches a booking to the payments.

The pertinent code follows:


Dim stDocName As String
Dim stLinkCriteria As String

stLinkCriteria = "tJDWPayments.jdwp_BookingRef =" & lngBookingID

lngNoPayments = DCount("jdwp_BookingRef", tJDWPayments","jdwp_BookingRef=" & lngBookingID)

stDocName = "fJDWEventPay"

DoCmd.OpenForm stDocName, , , stLinkCriteria, , acDialog


In debugging the code I observe that:

lngNoPayments = 3 – this is correct and verified by opening the table and setting the filter to ‘jdwp_BookingRef=11211’

stLinkCriteria = “tJDWPayments.jdwp_BookingRef=11211”

Yet when fJDWEventPay opens it shows only one record.  The record does match the filter in that the booking ref is 11211.
Microsoft Access

Avatar of undefined
Last Comment
DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
Avatar of mbizup
mbizup
Flag of Kazakhstan image

You are effectively setting the control source to one record like this.

If you want all the records, but filtered to a given subset, do this:

DoCmd.OpenForm stDocName,,,,,, acDialog, stlinkcriteria

and in the open event of your popup form:

Me.Filter = stlinkcriteria
Me.FilterOn = True



Avatar of mbizup
mbizup
Flag of Kazakhstan image

Hmm... I may be misreading your question.

Are you sure only one record is present in your form (ie: the bottom of the popup form says something like "record 1 of 1 records"?

Is it possible that you are just seeing the first record of three due to the default view being single form view vs datasheet or continuous forms?
Avatar of mbizup
mbizup
Flag of Kazakhstan image

Also check the Filter property of your popup form to see if there might be anything else narrowing down the results.
Avatar of MikeDTE
MikeDTE
Flag of United Kingdom of Great Britain and Northern Ireland image

ASKER

Hi there

I'm about to try your suggestion in your first post.

There are definately 3 records in th3 table matching teh filter but only on shows in the form - I've re-enabled the record  navigation buttons and it shows 1 of 1 (filter).

The form filter property is blank and there is nothing else in the properties that would narrow the results.

Back in 10
Avatar of MikeDTE
MikeDTE
Flag of United Kingdom of Great Britain and Northern Ireland image

ASKER

OK - tried your suggested code - this results in a compile error "Wrong number of arguements or invalid assignment"

Also in Form_Load of the child form

 Me.Filter = stLinkCriteria
 Me.FilterOn = True

This does nothing because stLinkCriteria is locally scoped in the parent form and not available in the child form - so the filter is set to nothing.
Do you happen to have the Form Data Entry property set to Yes?

mx
Avatar of MikeDTE
MikeDTE
Flag of United Kingdom of Great Britain and Northern Ireland image

ASKER

On the child form - Yes

On the parent form - No

Don't recall setting Data Entry to Yes
ASKER CERTIFIED SOLUTION
Avatar of DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
"On the child form - Yes"
I was referring to the Popup form.  That would show Record 1 of 1 ... BUT ... you would not see your single filtered record either.

mx
Avatar of MikeDTE
MikeDTE
Flag of United Kingdom of Great Britain and Northern Ireland image

ASKER

All working with the last code modifications

Thank you - one last question should the Data Entry property be set to Yes on the Child (Pop-up) form?
"should the Data Entry property be set to Yes on the Child (Pop-up) form?"
No.  That was just a long shot guess at that the problem. As I noted, that would result in no records showing.

What you originally have *should* work.  I tested that scenario here ... no problem. But, I don't have your system.  So, what I posted was just an alternate way to do it ... and I guess we got lucky :-)

mx
Microsoft Access
Microsoft Access

Microsoft Access is a rapid application development (RAD) relational database tool. Access can be used for both desktop and web-based applications, and uses VBA (Visual Basic for Applications) as its coding language.

226K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo