Form Handling when Record not Found (1 Viewer)

bergis

New member
Local time
Today, 17:47
Joined
Oct 21, 2011
Messages
1
I am looking for a way to handle an open form when there is no data found for a particular selection filter. I get a blank form with no way to go back to previous forms or close without closing form with R click of mouse and going back manually to the previous form.

Any help is appreciated a Beginner to Intermediate Access user.

JB
 

JamesMcS

Keyboard-Chair Interface
Local time
Today, 23:47
Joined
Sep 7, 2009
Messages
1,819
You could use something like DCount I would think.
Code:
Sub form_open()
If dcount("*","FormRecordsource","[Filterfield]=Filtercriteria")=0 then
Msgbox "Nothing to display"
form.close
Or something along those lines....
 

vbaInet

AWF VIP
Local time
Today, 23:47
Joined
Jan 22, 2010
Messages
26,374
You could use something like DCount I would think.
Code:
Sub form_open()
If dcount("*","FormRecordsource","[Filterfield]=Filtercriteria")=0 then
Msgbox "Nothing to display"
form.close
Or something along those lines....
You will do the above from JamesMcS on the Click event of the button and there's a slight change:
Code:
If DCount("*","[COLOR=black][B]FormRecordsource[/B][/COLOR]","[Filterfield]=Filtercriteria")=0 then
    MsgBox "Nothing to display"
Else
    DoCmd.OpenForm "FormName", acNormal
End if
Where FormRecordSource is the name of the query bound to your form. Yes, it needs to be a query.
 
Last edited:

JamesMcS

Keyboard-Chair Interface
Local time
Today, 23:47
Joined
Sep 7, 2009
Messages
1,819
Ah, but what if there are records in the recordsource, just not matching whatever filter criteria the user has selected?

Misread the open for bit as form open, dummy....
 

JamesMcS

Keyboard-Chair Interface
Local time
Today, 23:47
Joined
Sep 7, 2009
Messages
1,819
Might also be worth mentioning that the filtercriteria bit of that could be passed from elsewhere as a variable:
Code:
If DCount("*","Formrecordsource","[Filterfield]=" & variablename)
or if the filter is a string,
Code:
If DCount("*","Formrecordsource","[Filterfield]='" & variablename"'")
 

Users who are viewing this thread

Top Bottom