A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

No Data Selected for Form



 
 
Thread Tools Display Modes
  #1  
Old September 6th, 2009, 11:06 PM posted to microsoft.public.access.forms
Rillo
external usenet poster
 
Posts: 24
Default No Data Selected for Form

I have a form based on a query.
In the event that the query does not find any matching records, I want to
inform the user that this is the case.
At the moment all that happens is that a blank form appears.

I want to avoid using code if possible, so I have created a macro as
follows.....

IsNull([Forms]![Enquiry by Loan Expiry Date]![Description]) MsgBox

IsNull([Forms]![Enquiry by Loan Expiry Date]![Description]) Close Form

The intention is that a message box will be displayed to the effect that
there are no matching records and the form will then be closed.

I can't seem to work out into which event on my form I should insert the
macro.

Please advise.


--
Thanks in anticipation.
  #2  
Old September 7th, 2009, 12:59 AM posted to microsoft.public.access.forms
Tom Wickerath
external usenet poster
 
Posts: 3,914
Default No Data Selected for Form

Hi Rillo,

I can't seem to work out into which event on my form I should insert the
macro.


The following VBA code works in the Form_Open event. Not sure if it is
possible to cancle opening a form using a macro, as I pretty much avoid the
use of macros like the plague.

Option Compare Database
Option Explicit

Private Sub Form_Open(Cancel As Integer)
On Error GoTo ProcError

Dim strMessage As String
Dim strTitle As String

strMessage = "There are no records for the selected criteria."
strTitle = Me.Name & " form. No Records Available..."

If Me.Recordset.RecordCount = 0 Then
MsgBox strMessage, vbInformation, strTitle
Cancel = True
End If

ExitProc:
Exit Sub
ProcError:
MsgBox "Error " & Err.Number & ": " & Err.Description, _
vbCritical, "Error in Form_Open Procedure..."
Resume ExitProc
End Sub



Tom Wickerath
Microsoft Access MVP
http://www.accessmvp.com/TWickerath/
__________________________________________

"Rillo" wrote:

I have a form based on a query.
In the event that the query does not find any matching records, I want to
inform the user that this is the case.
At the moment all that happens is that a blank form appears.

I want to avoid using code if possible, so I have created a macro as
follows.....

IsNull([Forms]![Enquiry by Loan Expiry Date]![Description]) MsgBox

IsNull([Forms]![Enquiry by Loan Expiry Date]![Description]) Close Form

The intention is that a message box will be displayed to the effect that
there are no matching records and the form will then be closed.

I can't seem to work out into which event on my form I should insert the
macro.

Please advise.


--
Thanks in anticipation.

  #3  
Old October 12th, 2009, 06:17 AM posted to microsoft.public.access.forms
Theresa
external usenet poster
 
Posts: 176
Default No Data Selected for Form

Hi Tom and Rillo,
I simply want to close my form if it has no data. I have tried your code
below in the Form - On Open event but the form does not close.

If Me.Recordset.RecordCount = 0 Then
MsgBox strMessage, vbInformation, strTitle
Cancel = True
End If


Should the code be placed on another event?
Note: the form is linked to an underlying query.
  #4  
Old October 12th, 2009, 07:37 AM posted to microsoft.public.access.forms
Tom Wickerath
external usenet poster
 
Posts: 3,914
Default No Data Selected for Form

Hi Theresa,

I'm not understanding the issue that you are experiencing, because the line
of code that reads:
Cancel = True

should cancel opening of the form. Therefore, it should not have even opened
successfully...

Should the code be placed on another event?

No.

Is the message box statement being displayed?


Tom Wickerath
Microsoft Access MVP
http://www.accessmvp.com/TWickerath/
__________________________________________

"Theresa" wrote:

Hi Tom and Rillo,
I simply want to close my form if it has no data. I have tried your code
below in the Form - On Open event but the form does not close.

If Me.Recordset.RecordCount = 0 Then
MsgBox strMessage, vbInformation, strTitle
Cancel = True
End If


Should the code be placed on another event?
Note: the form is linked to an underlying query.

  #5  
Old November 18th, 2009, 06:44 PM posted to microsoft.public.access.forms
javablood
external usenet poster
 
Posts: 84
Default No Data Selected for Form

Tom,

Thanks, that is just what I needed to know. Now, how do I surpress the
Error 3021: No Current Record. message?

I commented out the ProcError but the MS error (above) keeps coming up after
the first message box comes up and after the program returns me to the form
from which I called the other form to open. I also set warnings off until I
leave the sub.

perplexed.
--
javablood


"Tom Wickerath" wrote:

Hi Theresa,

I'm not understanding the issue that you are experiencing, because the line
of code that reads:
Cancel = True

should cancel opening of the form. Therefore, it should not have even opened
successfully...

Should the code be placed on another event?

No.

Is the message box statement being displayed?


Tom Wickerath
Microsoft Access MVP
http://www.accessmvp.com/TWickerath/
__________________________________________

"Theresa" wrote:

Hi Tom and Rillo,
I simply want to close my form if it has no data. I have tried your code
below in the Form - On Open event but the form does not close.

If Me.Recordset.RecordCount = 0 Then
MsgBox strMessage, vbInformation, strTitle
Cancel = True
End If


Should the code be placed on another event?
Note: the form is linked to an underlying query.

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 09:20 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.