473,395 Members | 2,446 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

No Records returned hides form controls

19
Quick question that I can't find a solution to:

I have an ADP application that uses SQL Server 2000 backend, along with stored procedures that populate my forms. I do not want to use subforms for various reasons, so my data is loaded into a single form (record source is a stored procedure, and the form's InputParameters are changed depending on the data to load, pretty standard).

However, if no records are returned by the procedure, all the controls in the Detail section of the form are hidden. This wasn't a problem when I used subforms because I had navigation controls on the parent, and those weren't impacted.

However, now all my navigation controls are in the detail section of the form, so if records are not returned all the controls are hidden and I can't use any of the controls I need to modify the parameters to return a valid record set.

Anybody come across this before and have a fix? Such as making the form display the controls with Null data in the event no records are returned from the stored procedure?
Nov 14 '07 #1
12 3116
missinglinq
3,532 Expert 2GB
Usually you see this when no records are returned and AllowAdditions Property for the form is set to No. Is that the case here? If so, can you set AllowAdditions to Yes?

Welcome to TheScripts!

Linq ;0)>
Nov 14 '07 #2
binky
19
AllowAdditions is set to NO currently.

I do not want to allow additions to the recordset that i'm displaying though, which is why it's set to NO.
Nov 14 '07 #3
binky
19
I fixed it!

I added the following to the Form's BeforeInsert property:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_BeforeInsert(Cancel As Integer)
  2.     Cancel = True
  3. End Sub
Now the form loads with blank controls that can't be edited, then can be edited once a valid recordset is loaded.
Nov 14 '07 #4
binky
19
Take it back, I thought I fixed it.

Suddenly not working again :(
Nov 14 '07 #5
missinglinq
3,532 Expert 2GB
So, when you do have a valid recordset loaded, you never need to enter new records thru this form?

Linq ;0)>
Nov 14 '07 #6
binky
19
Correct, this record set is for viewing and updates only.

No deletes or additions on this form.
Nov 14 '07 #7
missinglinq
3,532 Expert 2GB
Good hack!

Linq ;0)>
Nov 14 '07 #8
binky
19
Not good enough unfortunately, it's still not working consistently :/
Nov 14 '07 #9
missinglinq
3,532 Expert 2GB
I don't have time to thouroughly test this and, in truth, don't know all the ins and outs of what you're doing, but I think this will work for you. Leave AllowAdditions set to Yes. Now use this code:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Dirty(Cancel As Integer)
  2. If RecordsetClone.RecordCount < 1 Then
  3.   MsgBox "You must pick new parameters for record retrieval"
  4.   Cancel = True
  5. Else
  6.   Me.AllowAdditions = False
  7. End If
  8. End Sub
Even with an empty recordset, the controls will remain visible, but if a user tries to enter a new record, they'll get the message telling them they need to pick new criteria for displaying records. You can, of course, change the message to suit your needs. When a valid recordset exists, the AllowAdditions will be set to False if the user tries to enter a new record.

Linq ;0)>
Nov 14 '07 #10
maxamis4
295 Expert 100+
I know that on dirty should work with changes but sometimes access is funny. Really i am serious try adding the form.refresh after that statement.
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Dirty(Cancel As Integer)
  2. If RecordsetClone.RecordCount < 1 Then
  3.   MsgBox "You must pick new parameters for record retrieval"
  4.   Cancel = True
  5. Else
  6.   Me.AllowAdditions = False
  7. End If
  8.  
  9. form.refresh
  10. End Sub
Nov 14 '07 #11
missinglinq
3,532 Expert 2GB
Whether you're "serious" or not, the fact is that there is absolutely no reason to use Refresh here! Refresh is only valid in a multi-user environment, to begin with, and then is only used to show UserA changes that have been made to the currently open recordset by UserB or UserC and so forth. It is not the same thing as a Requery, which many people get it confused with, and will not save data to the underlying table.

The problem that many people have with the Dirty property is in not understanding how it works. Once a record is Dirty, it remains Dirty until the record is saved. If something is set to occur when a record becomes dirty, and a change is made to the record, the event based on the record being Dirty is executed. If another change is made to the record, however, the OnDirty event will not be executed again! It only fires when the record intially becomes Dirty.
Nov 15 '07 #12
Jim Doherty
897 Expert 512MB
Take it back, I thought I fixed it.

Suddenly not working again :(
The way you should consider dealing with this is in SQL Server.

Using stored procedures where parameters are passed can result visually in a recordset of no 'depth' at all in other words typical 'snapshot' behaviour and that can be caused where multiple tables might be drawn together making a recordset 'uneditable' in the true sense on the application side.

Where this is likely to take place from a design perspective you should consider making use of the keyword EXISTS on the server side stored procedure to return at least something to the client application that informs the user that in actual fact, 'no record exists' for the dataset requested. This is NOT a workaround it is proper implementation of existing commands to ensure your application runs as you would want or expect.

A viable technique you should consider employing for yourself might be something like this:

Imagine you have a table called tblPerson consisting of Person_Id and PersonName. Two fields the primary being Person_Id (Go ahead create the table for yourself and populate it with data)

Now imagine you have a table called tblPersonAddress consisting of Person_ID and PersonAddress and AddressType. (Address type might typically store information to describe the building ie: house, flat, Apartment, Commercial etc)

Person_Id in the tblPersonAddress table is the foreign key. (Go ahead create the table for yourself and populate it with some data and include in it relevant numeric keys to enable a 'join' between Person_Id's from both tables)

Now imagine you have a table called tlkpAddressTypes with one single field called AddressType that contains descriptive data ie House,Flat,Apartment,Commercial (Go ahead create the table and populate it with data sufficient to enable a join between AddressType(the primary in this table with AddressType the foreign key in tblPersonAddress)

When all three of these tables are joined together in a 'View' or 'query' in Access then it becomes uneditable because updating/adding of data is only supported on one side of a two table join and even then you have to 'identify' the single table that can be updated in that two table join statement (this is done in an ADP file via the 'Unique Table' property setting of the form) The net effect then with more than two tables is that it becomes an unditable snapshot.

So lets have a look at the stored procedure that would return a dataset of at least 'something' that we could use in the ADP so as NOT to give us the blank screen you speak of:

This a a stored procedure based around the previous example tables I mentioned. For readability/brevity I have made it relate to a query/view called qryPerson which basically is a join between all three tables. You might want to do that first and save as a view/query

Expand|Select|Wrap|Line Numbers
  1. CREATE PROCEDURE dbo.usp_RetrievePerson
  2. (@PName varchar(35))
  3. AS
  4. SET NOCOUNT ON
  5. DECLARE @mycount bit
  6. IF EXISTS (Select Person_Id, PersonName FROM dbo.qryPerson WHERE PersonName=@PName)
  7. BEGIN
  8. SELECT Person_Id, PersonName FROM dbo.qryPerson WHERE PersonName=@PName
  9. END
  10. ELSE
  11. SELECT null as Person_ID, 'No Records' AS PersonName
  12. GO
  13.  
So what is this procedure doing? well by using the EXISTS keyword it is testing to determine if at least ONE record exists basing itself on that SELECT statement with criteria. If the condition is satisfied then it executes the SELECT on the server and returns the appropriate dataset to the client.

We could you may think use COUNT but remember EXISTS exits out of the test as soon as it find at least 'one' record whereas COUNT would count the entire table which becomes a performance hit on large datasets.

If the EXISTS condition is NOT satisfied ie: there are no records resulting from the SQL statement, then the second SQL statement is executed as part of the ELSE logic and this returns a single row of data where null is returned, representing Person_Id together with the words 'No Records' representing the column data output for the field PersonName. Here then we have an aside benefit in that seeing a recordset like this on screen, serves if you like as a message to the user that no records exist the server having tested the criteria logic and returned nothing at all.

Hope this helps you by looking at 'method' in perhaps a different way. Obviously any implementation of this on your side requires adjustment of anything given here to suit you.

Regards

Jim :)
Nov 15 '07 #13

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: (Pete Cresswell) | last post by:
..DefaultView = Continuous Forms ..RecordSource = a query. While the form & subform are open, I can open up the .RecordSource query and see five records. If I insert a record, then re-open...
12
by: MLH | last post by:
I have created two forms: frmBrowseNegsMainform and frmBrowseNegsSubform. I put a subform control on the first of these. The SourceObject property for the subform control is, of course,...
6
by: MS | last post by:
Access 97 here. I want a simple way to "lock" certain records on a form. Some records remain "live" until all data is available which happens over time. When all the fields are complete, I want...
4
by: MLH | last post by:
I have a combo box control on a form and a text box beside it in which I would like to display the number of listings in the combo-box. The combo box lists more or fewer rows depending on the...
1
by: mursyidatun ismail | last post by:
Dear all, database use: Ms Access. platform: .Net i'm trying to update a record/records in a table called t_doctors by clicking da edit link provided in the database. when i ran through da...
3
by: Wayne Brantley | last post by:
VS2005 RTM Create a web user control to use as a base class for other web user controls. Now, create a new web user control, change the class it inherits from to your base class and compile....
2
by: Antonio | last post by:
Can someone tell me why the following procedure updates ALL the records in the database with the field being updated for one record? private void updateRow(object source,...
10
by: 60325 | last post by:
This is the page where I collect the data in drop-down boxes with values of 1-10 and send it to a submitted page to do calculations. Example: Employee1 TeamScore(1-10) Employee2 ...
3
by: Martijn Mulder | last post by:
When I place both a MenuStrip and a Button on my Form, the button covers part of the menu. I hate to mess around with the Size and Location properties of Controls, so normally I lay out my controls...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
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,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
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,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.