I have a form based on a query. I would like to generate a msgbox and
close the form should the query return no records. [or not open the form
at all, either would be good]
TIA
R.
PS I would even be happy to lose the form and just do the same with the
query in datasheet view. 5 3090
normally, you'd trap for the NoData event of a report, but alas, this
isn't a report. I did get this to work, but I'd recommend that any
self-respecting Access programmer finish swallowing before reading
futher...
This works...
Private Sub Form_Load()
Dim rs As DAO.Recordset
Dim intRecords As Integer
Set rs = Me.RecordsetClo ne
'---you shouldn't need these two lines. You'll get 1 if there are
any records.
rs.MoveLast
rs.MoveFirst
If rs.RecordCount =0 Then
rs.Close
Set rs = Nothing
DoCmd.Close acForm, Me.Name, acSaveNo
Else
MsgBox rs.RecordCount & " records."
rs.Close
Set rs = Nothing
End If
End Sub
Even shorter:
Private Sub Form_Open(Cance l As Integer)
If Me.RecordsetClo ne.RecordCount = 0 Then
MsgBox "There are no records to display at this time." _
, vbInformation, "No Records"
Cancel = True
End If
End Sub
You will of course need to trap for and ignore Error 2501
in the code rountine that opens the form.
--
Jeff Conrad
Access Junkie
Bend, Oregon
<pi********@hot mail.com> wrote in message
news:11******** **************@ l41g2000cwc.goo glegroups.com.. . normally, you'd trap for the NoData event of a report, but alas, this isn't a report. I did get this to work, but I'd recommend that any self-respecting Access programmer finish swallowing before reading futher...
This works...
Private Sub Form_Load() Dim rs As DAO.Recordset Dim intRecords As Integer
Set rs = Me.RecordsetClo ne '---you shouldn't need these two lines. You'll get 1 if there are any records. rs.MoveLast rs.MoveFirst
If rs.RecordCount =0 Then rs.Close Set rs = Nothing DoCmd.Close acForm, Me.Name, acSaveNo Else MsgBox rs.RecordCount & " records." rs.Close Set rs = Nothing End If
End Sub
----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==---- http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
"Jeff Conrad" <je***@ernstbro thers.com> wrote in message
news:42******** **@127.0.0.1... Even shorter:
Private Sub Form_Open(Cance l As Integer) If Me.RecordsetClo ne.RecordCount = 0 Then MsgBox "There are no records to display at this time." _ , vbInformation, "No Records" Cancel = True End If End Sub
You will of course need to trap for and ignore Error 2501 in the code rountine that opens the form.
-- Jeff Conrad
Even shorter:
Private Sub Form_Open(Cance l As Integer)
If Me.RecordsetClo ne.RecordCount = 0 Then
MsgBox "There are no..."
Cancel = True
End If
End Sub
Tom Travolta wrote: "Jeff Conrad" <je***@ernstbro thers.com> wrote in message news:42******** **@127.0.0.1... Even shorter:
Private Sub Form_Open(Cance l As Integer) If Me.RecordsetClo ne.RecordCount = 0 Then MsgBox "There are no records to display at this time." _ , vbInformation, "No Records" Cancel = True End If End Sub
You will of course need to trap for and ignore Error 2501 in the code rountine that opens the form.
-- Jeff Conrad
Even shorter:
Private Sub Form_Open(Cance l As Integer) If Me.RecordsetClo ne.RecordCount = 0 Then MsgBox "There are no..." Cancel = True End If End Sub
Ok, thanks folks. I'll have to digest and try these. My VBA skills
aren't that good and I was hoping to do it with macro or form properties
if I could.
R.
highway of diamonds wrote: Tom Travolta wrote: "Jeff Conrad" <je***@ernstbro thers.com> wrote in message news:42******** **@127.0.0.1... Even shorter:
Private Sub Form_Open(Cance l As Integer) If Me.RecordsetClo ne.RecordCount = 0 Then MsgBox "There are no records to display at this time." _ , vbInformation, "No Records" Cancel = True End If End Sub
You will of course need to trap for and ignore Error 2501 in the code rountine that opens the form.
-- Jeff Conrad
Even shorter:
Private Sub Form_Open(Cance l As Integer) If Me.RecordsetClo ne.RecordCount = 0 Then MsgBox "There are no..." Cancel = True End If End Sub
Ok, thanks folks. I'll have to digest and try these. My VBA skills aren't that good and I was hoping to do it with macro or form properties if I could.
R.
Yes!!! works well, thanks very much.
I don't use Access much these days [or Vis Basic], this was a project I
was asked to do, got it up and running but small things like this make a
lot more user friendly. Need to keep my hand in I think.
R. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Sans Spam |
last post by:
Greetings! I have a table that contains all of the function
permissions within a given application. These functions are different
sections of a site and each has its own permissions (READ, WRITE,
UPDATE, DELETE) which are controlled by a web frontend and the table
records are manipulated to control the permissions.
Example:
The Press Release section record would look like this:
Username: John Doe
Function Name: Press Release
|
by: Steve |
last post by:
Form FrmRestock's recordsource is QryFrmRestock. The TransactionDate field's
criteria is set ats:
Forms!FrmRestock!LastXDays. LastXDays on the form is a combobox where the
selections are 30, 60 and 90. The default is set at 30.
Question1: When the form opens, there are no records displayed although there
are many records that fit the criteria of 30. If I put a button on the form to
do a requery and press the button, all the records...
|
by: Lyn |
last post by:
Hi,
I am working on a genealogy form. The only table (so far) lists everybody
in the family, one record per person. Each record has an autonum ID.
The parent form (frmMainForm) displays the data in each record, which
includes the ID of the father and the mother (who also have records in the
table). One record per form.
I have a Tab Control in the form, and in one of the tabs I have a subform
(sfmSiblings) in which I wish to list...
|
by: longtim |
last post by:
I have been having endless difficulty creating reports/queries that
set any relevent parameters from controls in forms.
I am creating an application under access 2003 but will target access
2000. The access file is in access 2000 format.
I have a form that will hold the relevent parameters for the
query/report that reports the statistics for all job records that
match a certain criteria. These are:
- A Customer Name.
|
by: piet |
last post by:
I have created a continues form, based on a query. In the header, there are
some comboboxes that gives the user the possibility to make certain
selections. Everytime a selection is made on a combobox, there is a VBA
action: ME.REQUERY. That works very fine: the user sees always the result of
his selection(s). There is also a textbox in the header that shows the
number of records in the form (Therefore I use DCOUNT).
Now I've got two...
| |
by: fumanchu |
last post by:
I've got to let end users (really just one person) load billing batch
files into a third party app table. They need to specify the billing
cycle name, the batch name, and the input file name and then I can use
these values to execute a SQL Server stored procedure to load them
into the batch table from the input file (the stored procedure uses
Dynamic SQL to Bulk Insert the file to a temp table then processes it
into the final table.)
My...
|
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 report" button
located on my form to print all of the list box values (that have been
updated via selection from combo boxes) from the form to the report.
I've tried using a macro with the code:
Macro Name: cmdGenerateReport : On Click
Action:...
|
by: JPG4 |
last post by:
I have tried just about everything that I can think of, so now I turn to you all for help!
I have created a form (titled "OAG") with an unbound textbox titled "DOW". I also have a Query that I have set up to return results using the abbreviations for the day of the week, and periods when that day is not present. For example, if the pattern is Monday, Wednesday, Friday, the query shows it as "Mon.Wed.Fri.." (periods replace Tues, Thurs, Sat,...
|
by: dizzydangler |
last post by:
Hi all,
I am a new Access user and just starting to get my head around some of the basic concepts, so please take it easy on me :) My company has been managing client records on excel, and I’m in the process of migrating the data over to Access 2007 (Windows XP), kind of learning as I go. I’ve managed to import the client records into a single table, and set up a “single view” form that streamlines how we input new client data. Now I’m...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |