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 » Running & Setting Up Queries
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

open a message box if a query is null during an autoexec macro



 
 
Thread Tools Display Modes
  #1  
Old April 28th, 2010, 05:33 PM posted to microsoft.public.access.queries
vander
external usenet poster
 
Posts: 1
Default open a message box if a query is null during an autoexec macro

Hope someone can help with this.

I have a query that runs using an AutoExec macro when the database opens.
What I want is for a message box to open instead of the query results window,
telling me if the query produced any records. I can do this easily enough
through a command button on a form, but cant figure out how to do it through
an autoexec macro at startup.

Any suggestions?

  #2  
Old April 28th, 2010, 06:56 PM posted to microsoft.public.access.queries
Dorian
external usenet poster
 
Posts: 542
Default open a message box if a query is null during an autoexec macro

You need to have your Autoexec macro run a VB function (macro action
RunCode)that executes the query and captures the count of records retrieved.

Dim strSQL as string
Dim k as integer
Dim rs as new ADODB.recordset
strSQL = "SELECT count(*) As K FROM MyTable WHERE........."
rs.Open strSQL, CurrentProject.Connection, adOpenForwardOnly, adLockReadOnly
If rs.EOF Then
k = 0
Else
k = rs.Fields("K").Value
End If
Msgbox "Found " & K & " records",,"Record Count"

-- Dorian
"Give someone a fish and they eat for a day; teach someone to fish and they
eat for a lifetime".


"vander" wrote:

Hope someone can help with this.

I have a query that runs using an AutoExec macro when the database opens.
What I want is for a message box to open instead of the query results window,
telling me if the query produced any records. I can do this easily enough
through a command button on a form, but cant figure out how to do it through
an autoexec macro at startup.

Any suggestions?

.

 




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 08:17 AM.


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